SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    United Kingdom
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why am I getting a mysql_fetch_array error?

    I have written the following code:

    Code:
    $Qs = mysql_query("SELECT Race_ID, Points_ID, Element_ID FROM Race_Details WHERE Race_ID LIKE '%".$searchrace."%' AND Points_ID LIKE ''Q%'' ORDER BY Points_ID ASC",$db); 
    
    while ($record1 = mysql_fetch_array($Qs)) {
    echo $record1["Points_ID"];
    echo $record1["Element_ID"];
    }
    but keep getting the error:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    Why?

  2. #2
    SitePoint Guru defiance's Avatar
    Join Date
    Oct 2004
    Location
    United states
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $Qs mysql_query("SELECT Race_ID, Points_ID, Element_ID FROM Race_Details WHERE Race_ID LIKE '%".$searchrace."%' AND Points_ID LIKE ''Q%'' ORDER BY Points_ID ASC",$db); 

    $numrows mysql_num_rows($Qs);

    for (
    $i=0$i<$numrows$i++){
    $record1 mysql_fetch_array($Qs)
    echo 
    $record1["Points_ID"];
    echo 
    $record1["Element_ID"];

    try that
    untested...
    but looks alright

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    United Kingdom
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I'm getting this:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

    Same as before but with the mysql_num_rows this time

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    United Kingdom
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sorted it out - it was because I had double single quotes around the Q% in the query... changed it from ''Q%'' to 'Q%' and it all worked

  5. #5
    SitePoint Member bhinard's Avatar
    Join Date
    Jan 2005
    Location
    Caen
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you've got problem with $db, $db must be link identifier returned by mysql_connect()


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
  •