Jump to content

Help needed!!! SQL Query..


xiaoxin22

Recommended Posts

i did this..

 

$query2 = sprintf("SELECT *  FROM (c_details INNER JOIN c_color ON c_details.cc_id = c_color.cc_id)  WHERE c_color.cc_id = %s",

mysql_real_escape_string($colour));

$result2 = mysql_query($query2);

$print2 = mysql_fetch_assoc($result2);

 

it is working but it keep showing error message..

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/sip/public_html/test/calender.php on line 90

 

can someone tell me what's wrong with it?

Link to comment
https://forums.phpfreaks.com/topic/206364-help-needed-sql-query/
Share on other sites

The problem is you where passing $result2 to mysql_fetch_assoc without first checking to make sure your query succeeded. mysql_fetch_assoc expects a result resource, which is what mysql_query returns if it succeeds, but when it fails it returns false.

 

While your at it, you should likely check your query returns some records as well.

 

$query2 = sprintf("SELECT *  FROM (c_details INNER JOIN c_color ON c_details.cc_id = c_color.cc_id)  WHERE c_color.cc_id = %s", mysql_real_escape_string($colour));
if ($result2 = mysql_query($query2)) {
  if (mysql_num_rows($result2)) {
    $print2 = mysql_fetch_assoc($result2);
  } else {
    // no records found.
  }
} else {
  // query failed
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.