Page 1 of 1
php error problem(Mysql error)
Posted: Mon Dec 11, 2006 11:18 pm
by dharprog
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...
Posted: Mon Dec 11, 2006 11:25 pm
by feyd
Check the return value from
mysql_query().
Thank for reply
Posted: Mon Dec 11, 2006 11:28 pm
by dharprog
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
Posted: Mon Dec 11, 2006 11:34 pm
by feyd
The error you are receiving has only come when the query failed due to bad syntax or similar for myself.
Can you post your code (make sure to use the proper syntax highlighting tags..)
Posted: Tue Dec 12, 2006 12:07 am
by dharprog
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
Posted: Tue Dec 12, 2006 12:30 am
by dibyendrah
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
Is this the end of the snippet ? If yes, there are two curly braces missing for while and outer if block.
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']);
}
}
Posted: Tue Dec 12, 2006 1:44 am
by dharprog
dibyendrah wrote: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
Is this the end of the snippet ? If yes, there are two curly braces missing for while and outer if block.
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']);
}
}
Posted: Tue Dec 12, 2006 7:43 am
by feyd
Where do $offset and $limit come from? Are you sure they are set properly for this particular call? Have you checked what mysql_error() says?
Posted: Tue Dec 12, 2006 8:46 am
by dharprog
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
Posted: Tue Dec 12, 2006 10:05 am
by neel_basu
test
Code: Select all
$result = mysql_query($result) or die(mysql_error().mysql_errorno())
And Then Tell Whats The Error Message
Else This Error Message Is Possible If There Is No Field In That Table Named orders
Posted: Tue Dec 12, 2006 7:16 pm
by RobertGonzalez
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.
Posted: Tue Dec 12, 2006 10:45 pm
by neel_basu
I am Not Sure Whats Wrong Here
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']);
Posted: Tue Dec 12, 2006 11:15 pm
by dibyendrah
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());
Posted: Wed Dec 13, 2006 10:44 am
by RobertGonzalez
Also, can you post the section of code where the $offset and $limit vars are set?
Posted: Wed Dec 13, 2006 10:49 am
by neel_basu
Is It Parsing $offset and $limit As Strings ???????