Jump to content

Very Common Problem/ Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in


simeonC
Go to solution Solved by kicken,

Recommended Posts

Well mysql query will not execute there is nothing wrong with the syntax to my knowledge and its becoming a bother. Even had a seizure. So I have to turn to you guys... The bottom code is a function for a shopping cart. I am trying to connect to the database to extract all relevant lengths and colors for a particular product. Instead of returning a result set I get a boolean which must be 0. My question is what am I doing wrong and how can I fix it. This been going on forever.

 

 

 

function index_display($index_array){

foreach ($index_array as $row){

$length=mysql_query("SELECT * FROM many_lengthHair WHERE product_id='$row[product_id]'");

$length_array=mysql_fetch_array($length);

echo '<tr>';

echo '<th>';

echo ' <img name="product" src="uploads/'.$row['product_id'].'.jpg" width="120" height="110" alt="$row[product_id]">';

echo '<th>';

echo '<th width="143" valign="top" scope="col">';

echo $row['cat_name'] . '<br>' . $row['texture_name'] . '<br>';

/////Retreive Lengths for product_id

echo '<label>';

echo 'Lengths ·';

echo '<select name="length">';

do {

echo '<option value="';

echo $length_array['length_name']. '">';

echo $length_array['length_name'];

echo '</option>';

} while ($length_array=mysql_fetch_array($length));

echo '</select><br>';

/////Retreive Color for product_id

echo '<label>';

echo 'Color ·';

echo '<select name="length">';

do {

echo '<option value="';

echo $color_fetch['length_name']. '">';

echo $color_fetch['length_name'];

echo '</option>';

} while ($color_fetch=mysql_fetch_array($color_query));

echo '</select>';

 

echo '<br>';

echo '</th>';

echo '</tr>';

} //end of foreach loop

}

 

?>

Edited by simeonC
Link to comment
Share on other sites

I don't see any $color_query = mysql_query(...) line in that code, but yet you are trying to use $color_query in mysql_fetch_array.

 

Also you should use a while() loop to process your query results, not a do/while loop.

Link to comment
Share on other sites

  • Solution

Add some error reporting, that way PHP will inform you of any errors rather than you wasting time trying to guess.

 

$length=mysql_query("SELECT * FROM many_lengthHair WHERE product_id='$row[product_id]'");
if (!$length){
   echo mysql_error();
   exit;
}
Link to comment
Share on other sites

Funny I tried the mysql_error() function and I never got anything back had no idea it had to be echoed. You are the best its working like a well oiled engine.Thank you. praises. what can I do  to show you my appreciation.

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.