rasikasol Posted January 19, 2007 Share Posted January 19, 2007 This is the code:<?phpif($categories_id!=''){ $sqln = "SELECT p.products_id FROM zesta_products AS p, zesta_products_to_categories AS c WHERE p.products_id = c.products_id AND c.categories_id = '".$categories_id."' ORDER BY $sort_by $sort_order LIMIT $start,$max_results"; $resultn = mysql_query($sqln,$conn) or die('Query failed50: ' . mysql_error());}//$sql = mysql_query("SELECT * FROM pages"); ?> <?php$products = array();while($rown = mysql_fetch_array($resultn)){ array_push($products,$rown[0]); //$products_no=$rown[0]; //echo $rown[0]; } ?>This is the error:mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wamp\www\www.zesta.com\zesta_products\zesta_cart.php on line 230line 230 ----- while($rown = mysql_fetch_array($resultn)){ ---------Yesterday it worked just fine, now I get this error.Do you have any ideas? Link to comment https://forums.phpfreaks.com/topic/34869-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource-in/ Share on other sites More sharing options...
paul2463 Posted January 19, 2007 Share Posted January 19, 2007 php variables in mysql queries have to have a single tick around them try this for your query[code]<?php$sqln = "SELECT p.products_id FROM zesta_products AS p, zesta_products_to_categories AS c WHERE p.products_id = c.products_id AND c.categories_id = '$categories_id' ORDER BY '$sort_by', '$sort_order' LIMIT '$start','$max_results'";?>[/code]if it is saying that the suppl;ied argument is not a valid results resource then the query does not make sense Link to comment https://forums.phpfreaks.com/topic/34869-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource-in/#findComment-164385 Share on other sites More sharing options...
JayBachatero Posted January 19, 2007 Share Posted January 19, 2007 You don't need to leave php and get back in php since it's all together. The query and while block. Also since the while block is outside the [tt]if ($categories_id != '')[/tt] if $categories_id is empty then the while loop will run but it wont have a valid resource to get the results from. Also I suggest using mysql_fetch_assoc() over mysql_fetch_array().[code]<?phpif ($categories_id != ''){ $sqln = " SELECT p.products_id FROM zesta_products AS p, zesta_products_to_categories AS c WHERE p.products_id = c.products_id AND c.categories_id = '$categories_id' ORDER BY $sort_by $sort_order LIMIT $start, $max_results"; $resultn = mysql_query($sqln, $conn) or die('Query failed50: ' . mysql_error()); $products = array(); while ($rown = mysql_fetch_assoc($resultn)) { array_push($products, $rown['products_id']); //$products_no=$rown[0]; //echo $rown[0]; }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/34869-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource-in/#findComment-164405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.