mysql_num_rows() error

Hi,
maybe you could help me. First function is working perfectly, but second one doesn’t and it shows Warning: on line 50 $num_rows = mysql_numrows($result);
I don’t know what to do because both functions are very similar. What i do wrong? Maybe it’s because i putting variable to function from mysql_result()?

<? function displayTerms(){ global $database; $q = "SELECT ID,terminai,reiksme " ."FROM ".TBL_TERM." ORDER BY terminai DESC"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Lentelė tuščia."; return; } /* Display table contents */ echo "\n"; echo "\n"; for($i=0; $i<$num_rows; $i++){ $terid = mysql_result($result,$i,"ID"); $uterm = mysql_result($result,$i,"terminai"); $ureiksm = mysql_result($result,$i,"reiksme"); $linkcom="Komentuoti"; echo "\n"; displayComments($terid); } echo "
Terminas Reikšmė
$uterm $ureiksm $linkcom

\n"; } ?> <? function displayComments($id){ global $database; $q = "SELECT comment " ."FROM ".TBL_COMMENT."WHERE terid='$id'"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Lentelė tuščia."; return; } /* Display table contents */ echo "\n"; echo "\n"; for($i=0; $i<$num_rows; $i++){ $ucomm = mysql_result($result,$i,"comment"); echo "\n"; } echo "
Termino komentarai
$ucomm

\n"; } ?>

No sure, but, this line:
$result = $database->query($q);
is a MySQLi command…

And, this line:
$num_rows = mysql_numrows($result);
is a MySQL command…

I do not think you can mix them… You would have to change the num_rows to something in MySQLi format, something like this:
$result = $database->query($q);
/* Error occurred, return given name by default */
$num_rows =$result=>mysql_num_rows;

You should Google both MySQL and MySQLi to understand the formats for each. From what I have read, MySQLi is more modern, but, most programmers say MySQL is a bit faster. Either work well for most sites. Good luck…

SORRY SORRY!!! I pressed send before reading my own note…

This is the correct version of that line, not the one I sent you!

$num_rows = $result->num_rows;

Sorry for the flying fingers…

thanks for your help. But i don’t think that this is a problem. In first line you mentioned it was calling to my database class in which there is this function [php] function query($query){
return mysql_query($query, $this->connection);
}
[/php]

Well, you are attempting to change a PHP MySQLi query into a function? That will not work.
When you use that first line, $result = $database->query($q); , the PHP engine will first look at
whatever you have installed into $database and use the “query” function in there, not yours.
So, your “function” should never be called. And, why would you want to sub-class a MySQLi function?
That makes no sense to me. Perhaps to you or I may be missing something…

Either way, good luck with it…

Hello vuras, i think your $q sql query is wrong. replace(remove) your below line from displayComments() function.(Second function) [php] $q = "SELECT comment "."FROM ".TBL_COMMENT."WHERE terid='$id'";

[/php]
use below query
[php]
//use below code
$q = “SELECT comment FROM “.TBL_COMMENT.” WHERE terid=”.$id;
[/php]
i hope this will helpful for you.
Reply your feedback
SR

thank you, your post was very helpful, i replaced query with yours and function is working :slight_smile:

Hello vuras, It's rally nice to hear that your issue is resolve. Post other issues and query. ~~SR~~
Sponsor our Newsletter | Privacy Policy | Terms of Service