Jump to content

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


simeonC

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

}

 

?>

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.

Decided to leave the $color_query out because it is structured the same reduce redundancy. but my errors are coming from the $length_query... I just do not kow what I am doing wrong. will change to while also

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

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.

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.