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
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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.