954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Warning: mysql_num_rows():

Can anyone help..... When I search on my site this is the error I get

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /mounted-storage/home23a/sub003/sc21979-KVVZ/www/ghhookup/functions.php on line 28


This is a peice of the code from function.phpif(mysql_num_rows($sql_res)){
return mysql_fetch_object($sql_res);
}
else {
return '';
}
}
elseif($wtr=='num'){
return mysql_num_rows($sql_res);
}
elseif($wtr=='res'){
return $sql_res;
}
}

welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 

Is this the offending line?
return mysql_num_rows($sql_res);

If so, you are getting a zero result back and trying to return that. Can you post the whole function?

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 
Is this the offending line? If so, you are getting a zero result back and trying to return that. Can you post the whole function?





yes that is the offending line

welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 

put that into an if statement and go from there.
[php]

if(mysql_num_rows($sql_res)) {
//do something fancy
} else {
exit ("there is no data for you here");
}

[/php]

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 
put that into an if statement and go from there. [php] if(mysql_num_rows($sql_res)) { //do something fancy } else { exit ("there is no data for you here"); } [/php]




So this is how is suppose to lookif(mysql_num_rows($sql_res)){
return mysql_fetch_object($sql_res);
}
else {
return '';
}
}
elseif($wtr=='num'){

if(mysql_num_rows($sql_res)) {
//do something fancy
} else {
exit ("there is no data for you here");
}

}



if not can you post it with everything

welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 

you can do that or you can do everything you need to in the first if statement. that will save you some code space.

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 

When I put that. every result put no data, but when I had the previous script it had data but with an error on top

welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 
When I put that. every result put no data, but when I had the previous script it had data but with an error on top

Without seeing the entire function, i cant really help you with logic.

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 


<? } ?>


<? require('templates/ad_header.php'); ?>


<?
}//function

//showing header
function show_header(){
?>

Demo Site
<?
$mode=form_get("mode");
$act=form_get("act");
if($mode=="user"){
?>

<?
}
elseif(($mode=='listing')&&($act=='create')){
?>

<?
}
elseif((($mode=='listing')&&($act!='create')&&($act!='show')&&($act!='feedback'))||(($mode=='search')&&($act=='listing'))){
?>

<?
}//elseif
?>


<? require('templates/header.php'); ?>


<?
}
//showing footer
function show_footer(){
?>


<? require("templates/footer.php"); ?>

welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 

Try this:

[php]
if(mysql_num_rows($sql_res)){
if($wtr=='get' || $wtr == 'num'){
return mysql_fetch_object($sql_res);
} elseif($wtr=='res'){
return $sql_res;
} else {
return;
}
}
[/php]
I dont know what you are trying to do by returning a mysql resource if wtr==res, but this should compact some of your logic.

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 
Try this: [php] if(mysql_num_rows($sql_res)){ if($wtr=='get' || $wtr == 'num'){ return mysql_fetch_object($sql_res); } elseif($wtr=='res'){ return $sql_res; } else { return; } } [/php] I dont know what you are trying to do by returning a mysql resource if wtr==res, but this should compact some of your logic.




When I put your script I recieved this:Parse error: syntax error, unexpected $end in /mounted-storage/home23a/sub003/sc21979-KVVZ/www/ghhookup/functions.php on line 4890

welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 

there is nothing syntaticlly wrong with the code i gave you, you must have copy and pasted it in correctly. You have a mis-matched { somewhere in there, maybe open the file in an IDE like zend or eclipse to figure out where the error is.

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 
there is nothing syntaticlly wrong with the code i gave you, you must have copy and pasted it in correctly. You have a mis-matched { somewhere in there, maybe open the file in an IDE like zend or eclipse to figure out where the error is.




Ok i am going to send you the file and can you please place the code for me and send it back.

Attachments functions.php (138.94KB)
welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 

No, you can do this, you need to know how to debug your own code. please do your own work.

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 
No, you can do this, you need to know how to debug your own code. please do your own work.



Sir i have done it several times. i am getting the same error

welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 


<? } ?>


<? require('templates/ad_header.php'); ?>


<?
}//function

//showing header
function show_header(){
?>

Demo Site
<?
$mode=form_get("mode");
$act=form_get("act");
if($mode=="user"){
?>

<?
}
elseif(($mode=='listing')&&($act=='create')){
?>

<?
}
elseif((($mode=='listing')&&($act!='create')&&($act!='show')&&($act!='feedback'))||(($mode=='search')&&($act=='listing'))){
?>

<?
}//elseif
?>


<? require('templates/header.php'); ?>


<?
}
//showing footer
function show_footer(){
?>


<? require("templates/footer.php"); ?>

welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 

I also trying deleting ?>

welbyobeng
Junior Poster in Training
75 posts since Oct 2006
Reputation Points: 13
Solved Threads: 0
 

deleting the ?> wont help as you need an ending tag for php, there is a mismatched bracket somewhere in your code, use a code editor like eclipse or zend ide to go through and debug your code.

sn4rf3r
Junior Poster
135 posts since Sep 2006
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You