php error problem(Mysql error)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

php error problem(Mysql error)

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Check the return value from mysql_query().
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Thank for reply

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..)
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post 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
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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']);
	}
}
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post 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']);
	}
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post 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
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post 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']);
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Print the SQL query to see what is really happening. :lol:

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());
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Also, can you post the section of code where the $offset and $limit vars are set?
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Is It Parsing $offset and $limit As Strings ???????
Post Reply