SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member Mung's Avatar
    Join Date
    Jun 2003
    Location
    Neston
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question mysql_fetch_array() error

    Can anyone help me to sort this out. I've been trying to get it to work for 2 days and my hair is starting to turn white.

    PHP Code:
    $result 'mysql_query(SELECT * FROM news);';
    if (
    $result){
        echo 
    "success!";
        }else{
    die (
    '<br>Error'.mysql_error());
    }

    while (
    $row mysql_fetch_array($result)) 
    {
    echo 
    "<p> ".$row[content]." </p>";

    It generates this error:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/spaceon/public_html/chickens/test.php on line 71

    Line 71 is the mysql_fetch_array.

    Thanks

  2. #2
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use this code:

    PHP Code:
    $result mysql_query("SELECT * FROM news") or die("Error: " mysql_error()); 

    while (
    $row mysql_fetch_array($result)) 

    echo 
    '<p> ' $row['content'] . ' </p>'

    You had the query function itself inside of quotes, which just made it into a string. That caused the query to not exists, and therefor the fetch to fail.
    Mike
    It's not who I am underneath, but what I do that defines me.

  3. #3
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One starts to wonder why he didn't put mysql_fetch_array() in quotes, too .

  4. #4
    SitePoint Member Mung's Avatar
    Join Date
    Jun 2003
    Location
    Neston
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you

    Icheb? Would it have made it go faster?

  5. #5
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Definitely .

  6. #6
    SitePoint Member Mung's Avatar
    Join Date
    Jun 2003
    Location
    Neston
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll add it now then

  7. #7
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But don't blame me if it doesn't work .

  8. #8
    SitePoint Member Mung's Avatar
    Join Date
    Jun 2003
    Location
    Neston
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's that fast it finishes before it's even started, what a great piece of custom code

  9. #9
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by naramation
    Use this code:

    PHP Code:
    echo '<p> ' $row['content'] . ' </p>'
    Come on Mike, go full throttle! (Umm, Angels)

    PHP Code:
    echo '<p> '$row['content'], ' </p>'
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  10. #10
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    :sigh:, I always forget

    Thanks for the tip, Sean
    Mike
    It's not who I am underneath, but what I do that defines me.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •