Canman2005 Posted May 17, 2007 Share Posted May 17, 2007 Hi all I have the following code <?php $db_name ="***"; $server = "localhost"; $dbusername = "***"; $dbpassword = "***"; $connection = mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error()); $db = mysql_select_db($db_name,$connection)or die(mysql_error()); $sql = "SELECT * FROM countries ORDER BY description ASC"; $query = @mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($query)) { $total = "SELECT COUNT(*) as Num FROM users WHERE `email` NOT LIKE '%@googlemail.com%' AND country_code = ".$row['code'].""; $results = mysql_result(mysql_query($total),0); ?> <?php print $row['description']; ?><br> <?php print $results; ?><br><br> <?php } ?> But when I run the page, I get the error Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/public_html/test.php Does anyone know why? I've checked and checked again, but cannot seem to find a answer Any help would be great Thanks Dave Link to comment https://forums.phpfreaks.com/topic/51819-mysql_result-error/ Share on other sites More sharing options...
jitesh Posted May 17, 2007 Share Posted May 17, 2007 Try this <?php $total = "SELECT COUNT(*) as Num FROM users WHERE `email` NOT LIKE '%@googlemail.com%' AND country_code = ".$row['code'].""; $results = mysql_query($total,$connection); $Num = mysql_result($results,0,'Num'); ?> Link to comment https://forums.phpfreaks.com/topic/51819-mysql_result-error/#findComment-255321 Share on other sites More sharing options...
xenophobia Posted May 17, 2007 Share Posted May 17, 2007 $results = mysql_result(mysql_query($total),0); One more argument, the field name of your table. mysql_result(mysql_query($total), 0, "field_1"); Link to comment https://forums.phpfreaks.com/topic/51819-mysql_result-error/#findComment-255323 Share on other sites More sharing options...
Canman2005 Posted May 17, 2007 Author Share Posted May 17, 2007 thanks, works fine now Link to comment https://forums.phpfreaks.com/topic/51819-mysql_result-error/#findComment-255324 Share on other sites More sharing options...
hvle Posted May 17, 2007 Share Posted May 17, 2007 that's because your query $total is not in correct syntax: fix: $total = "SELECT COUNT(*) as Num FROM users WHERE `email` NOT LIKE '%@googlemail.com%' AND country_code = '{$row['code']}'"; Link to comment https://forums.phpfreaks.com/topic/51819-mysql_result-error/#findComment-255327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.