SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    Texas
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_fetch_array()

    I've been trying to figure this out, but to no avail.

    I'm getting this error:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource [...] on line 52.

    PHP Code:
    // Request news information
    $title = @mysql_query("SELECT TITLE FROM news"); 
     if (!
    $title) { 
     echo(
    "<p>Error performing query: " mysql_error() . "</p>"); 
     exit();
      }
    $author = @mysql_query("SELECT AUTHOR FROM news"); 
     if (!
    $author) { 
     echo(
    "<p>Error performing query: " mysql_error() . "</p>"); 
     exit(); 
      }
    $news = @mysql_query("SELECT NEWS FROM news"); 
     if (!
    $news) { 
     echo(
    "<p>Error performing query: " mysql_error() . "</p>"); 
     exit();
      }
    $date = @mysql_query("SELECT DATE FROM news"); 
     if (!
    $date) { 
     echo(
    "<p>Error performing query: " mysql_error() . "</p>"); 
     exit();
      }
    // Display news
    $info mysql_query("SELECT ID, TITLE, AUTHOR, NEWS, DATE, FROM news ORDER BY ID DESC");
    while (
    $display mysql_fetch_array($info)) {
     
    $title=$display["TITLE"];
     
    $author=$display["AUTHOR"];
     
    $news=$display["NEWS"];
     
    $date=$display["DATE"];
    ?> 
    Line 52 is as follows:

    PHP Code:
    while ($display mysql_fetch_array($info)) { 
    Am I missing something?

  2. #2
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That usually means that there is something wrong with your query. Try copying the query and pasting it into phpMyAdmin and see if it works.

  3. #3
    o_O O_o BlueFire2k5's Avatar
    Join Date
    Mar 2003
    Location
    Sioux Falls, SD
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change this line...
    $info = mysql_query("SELECT ID, TITLE, AUTHOR, NEWS, DATE, FROM news ORDER BY ID DESC" );

    to this...
    $info = mysql_query("SELECT ID, TITLE, AUTHOR, NEWS, DATE, FROM news ORDER BY ID DESC" ) or print mysql_error();

    and see if it gives you an error.
    "Sa souvraya niende misain ye."
    - Robert Jordan, The Wheel of Time

  4. #4
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,811
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Silly question, but are all those fields uppercase in the DB?
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    remove the comma after DATE for starters. then see if there's still a problem.

    you should always add

    or die(mysql_error());

    after your mysql_query() lines and it will tell you what the problem is. very basic troubleshooting thing.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  6. #6
    o_O O_o BlueFire2k5's Avatar
    Join Date
    Mar 2003
    Location
    Sioux Falls, SD
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DR_LaRRY_PEpPeR
    remove the comma after DATE for starters. then see if there's still a problem.

    you should always add

    or die(mysql_error());

    after your mysql_query() lines and it will tell you what the problem is. very basic troubleshooting thing.
    Doh, I looked at his code and didn't even see that comma... o_o
    "Sa souvraya niende misain ye."
    - Robert Jordan, The Wheel of Time

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    Texas
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gah..

    Yep, that was it.

    The comma was the culprit.

    Thanks... I'm sure I'll be back, heh.


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
  •