phulla Posted March 1, 2006 Share Posted March 1, 2006 My local machine i havephp v4.3.10mysql v4.1.10-ntapache v2.0.50My uk2.net host hasphp v4.3.11mysql v4.0.24apache v1.3.33The following code works fine locally[code]<? if ($conn) { $result = $dbConn->queryDB( "SELECT * FROM ajmerphull_mainnav WHERE display = 1 ORDER BY id ASC" ); }?><div id="nav" class="fudge"> <ul> <? if (mysql_num_rows($result) >= 1) { $count = 1; while ($row = mysql_fetch_array($result)) { $last = ($count == mysql_num_rows($result) ? ' class="noborder"' : ''); print ( "<li". $last ."><b>[</b><a href=\"". $row['link'] ."\" accesskey=\"". $count ."\" title=\"". $row['title'] ."\">". $row['name'] ."</a><b>]</b></li> "); $count++; } } ?> </ul></div>[/code]Database class[code] function queryDB($sql) { return mysql_query($sql) or die(mysql_error()); }[/code]I can connect to the database i have replicated on the host using phpMyAdmin and execute the SQL statement and it returns the desired result.On the host, outputing the value of $result returns a value of 1, which is correct.I can not understand what's wrong with mysql_num_rows. If i remove the if statement, i get the same error for mysql_fetch_array.I can not print_r(mysql_fetch_array($result)) to check the value.Can anybody help?You can see this live at [a href=\"http://ajmerphull.com\" target=\"_blank\"]http://ajmerphull.com[/a]Thanks Link to comment https://forums.phpfreaks.com/topic/3825-error-mysql_num_rows/ Share on other sites More sharing options...
XenoPhage Posted March 1, 2006 Share Posted March 1, 2006 Hrm..Well, at first glance, it looks like you check to see if $conn is valid, but then you're calling it $dbConn when you do your query.. Are these 2 independent objects?Are you sure that $conn is valid each time? If $conn fails, then $result is never populated with a valid resource. So when you try to get the number of rows, it will fail.Try tossing some debug info in there. Inside the first if loop, do something like this :[code] if ($conn) { print "Connection is Valid"; $result = $dbConn->queryDB( "SELECT * FROM ajmerphull_mainnav WHERE display = 1 ORDER BY id ASC" ); } else { print "Invalid Connection!"; }[/code]Your second if statement could look something like this :[code] if (isset($result) && (mysql_num_rows($result) >= 1)) {[/code]I would recommend re-working this a bit, though. If you can't get a connection to the database, don't bother continuing. Display an error message instead of displaying partial data... Link to comment https://forums.phpfreaks.com/topic/3825-error-mysql_num_rows/#findComment-13269 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.