simeonC Posted May 26, 2013 Share Posted May 26, 2013 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 } ?> Link to comment https://forums.phpfreaks.com/topic/278408-very-common-problem-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-in/ Share on other sites More sharing options...
kicken Posted May 26, 2013 Share Posted May 26, 2013 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 https://forums.phpfreaks.com/topic/278408-very-common-problem-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-in/#findComment-1432402 Share on other sites More sharing options...
simeonC Posted May 26, 2013 Author Share Posted May 26, 2013 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 Link to comment https://forums.phpfreaks.com/topic/278408-very-common-problem-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-in/#findComment-1432408 Share on other sites More sharing options...
kicken Posted May 26, 2013 Share Posted May 26, 2013 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 https://forums.phpfreaks.com/topic/278408-very-common-problem-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-in/#findComment-1432411 Share on other sites More sharing options...
simeonC Posted May 26, 2013 Author Share Posted May 26, 2013 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 https://forums.phpfreaks.com/topic/278408-very-common-problem-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-in/#findComment-1432413 Share on other sites More sharing options...
DaveyK Posted May 27, 2013 Share Posted May 27, 2013 Marking his reply as the solving answer would work. Link to comment https://forums.phpfreaks.com/topic/278408-very-common-problem-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-in/#findComment-1432469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.