php error problem(Mysql error)
Moderator: General Moderators
php error problem(Mysql error)
Hi,
I'm retrieving orders from a table of records. When there are records no Error that shows fine all the records But when it comes to empty table query giving this error. why am i gettng this error? How can i avoid?
Error is :
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/peoplela/public_html/scripts/admin/admin_mng_orders.php on line 97
Thank YOU...
I'm retrieving orders from a table of records. When there are records no Error that shows fine all the records But when it comes to empty table query giving this error. why am i gettng this error? How can i avoid?
Error is :
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/peoplela/public_html/scripts/admin/admin_mng_orders.php on line 97
Thank YOU...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Check the return value from mysql_query().
Thank for reply
Hi
when i check the return value of the mysql_query() it returns some Resource id #2 like that its giving every time? what should we get the return value from that, then from which value we decide that its correct? what r the values do we get.
Clear me,
thank You for reply really..
Thank YOu
when i check the return value of the mysql_query() it returns some Resource id #2 like that its giving every time? what should we get the return value from that, then from which value we decide that its correct? what r the values do we get.
Clear me,
thank You for reply really..
Thank YOu
Hi
This is the code i'm using...
This is the code i'm using...
Code: Select all
$result = "select * from orders order by order_id DESC limit $offset, $limit ";
$result = mysql_query($result);
if(mysql_num_rows($result) >=1) {
while($row = mysql_fetch_array($result)){
$m = date("m", $row['date']);
$y = date("Y", $row['date']);
$d = date("d", $row['date']);
?>
Is there any syntax problem. when it is wrong it wont display the records also na
Thank YOU- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
Is this the end of the snippet ? If yes, there are two curly braces missing for while and outer if block.dharprog wrote:Hi
This is the code i'm using...
Code: Select all
$result = "select * from orders order by order_id DESC limit $offset, $limit "; $result = mysql_query($result); if(mysql_num_rows($result) >=1) { while($row = mysql_fetch_array($result)){ $m = date("m", $row['date']); $y = date("Y", $row['date']); $d = date("d", $row['date']); ?> Is there any syntax problem. when it is wrong it wont display the records also na Thank YOU
Should be :
Code: Select all
$result = "select * from orders order by order_id DESC limit $offset, $limit ";
$result = mysql_query($result);
if(mysql_num_rows($result) >=1) {
while($row = mysql_fetch_array($result)){
$m = date("m", $row['date']);
$y = date("Y", $row['date']);
$d = date("d", $row['date']);
}
}dibyendrah wrote:Is this the end of the snippet ? If yes, there are two curly braces missing for while and outer if block.dharprog wrote:Hi
This is the code i'm using...
Code: Select all
$result = "select * from orders order by order_id DESC limit $offset, $limit "; $result = mysql_query($result); if(mysql_num_rows($result) >=1) { while($row = mysql_fetch_array($result)){ $m = date("m", $row['date']); $y = date("Y", $row['date']); $d = date("d", $row['date']); } } ?> Is there any syntax problem. when it is wrong it wont display the records also na Thank YOU
Should be :
Code: Select all
$result = "select * from orders order by order_id DESC limit $offset, $limit "; $result = mysql_query($result); if(mysql_num_rows($result) >=1) { while($row = mysql_fetch_array($result)){ $m = date("m", $row['date']); $y = date("Y", $row['date']); $d = date("d", $row['date']); } }
Hi
I set correctly the $offset and $limit.
One thing i'm asking you, that is You are saying that it does have some wrong syntax or something but see what i said its giving me (I mean that query is working) the results and working with page navigation. When there is no record then only the error is coming for that i'm asking. So the query is not wrong when its displays the records.
What do you say ?
Thank YOu
I set correctly the $offset and $limit.
One thing i'm asking you, that is You are saying that it does have some wrong syntax or something but see what i said its giving me (I mean that query is working) the results and working with page navigation. When there is no record then only the error is coming for that i'm asking. So the query is not wrong when its displays the records.
What do you say ?
Thank YOu
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
test
And Then Tell Whats The Error Message
Else This Error Message Is Possible If There Is No Field In That Table Named orders
Code: Select all
$result = mysql_query($result) or die(mysql_error().mysql_errorno())Else This Error Message Is Possible If There Is No Field In That Table Named orders
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
If your variables for the limit are correct, the query should run without incident. Of the limit variables are not correct, you will get a syntax error. The mysql_error() function will tell you with some degree of clarity what the problem is. Maybe you can execute the query under the conditions that it is giving you problems and post the MySQL error message here so we can review that.
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
I am Not Sure Whats Wrong Here
But Try Changing The sql Variable From $result To Something Else
Thats
But Try Changing The sql Variable From $result To Something Else
Thats
Code: Select all
$sql = "select * from orders order by order_id DESC limit $offset, $limit ";
$result = mysql_query($sql);
if(mysql_num_rows($result) >=1) {
while($row = mysql_fetch_array($result)){
$m = date("m", $row['date']);
$y = date("Y", $row['date']);
$d = date("d", $row['date']);- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
Print the SQL query to see what is really happening.
Code: Select all
$sql_query = "select * from orders order by order_id DESC limit ".$offset.", ".$limit ;
print $sql_query;
$result = mysql_query($sql_query) or die(mysql_error().mysql_errorno());- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA