Jump to content

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in


rasikasol

Recommended Posts

This is the code:

<?php
if($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 230


line 230  -----  while($rown = mysql_fetch_array($resultn)){  ---------

Yesterday it worked just fine, now I get this error.

Do you have any ideas?
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
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]
<?php

if ($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]

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.