Johns3n Posted March 31, 2012 Share Posted March 31, 2012 Hi PHPfreaks.com I'm having some trouble with some code that should be straight forward! When i run following code: <?php $content->query(mysql_real_escape_string($_GET['slug'])); ?> it does the following: <?php class content { public function query($slug){ if(empty($slug)){ $slug = "forside"; } $query = sprintf("SELECT id FROM komoono_sider WHERE slug = '".$slug."'"); $result = mysql_query($query); echo count($result); } } $content = new content; ?> If the slug variable is empty it should be set to "forside" and when i set it to some values that i KNOW are in the database it all works perfectly and the count is correct! However when i set the slug variable to something i KNOW that isn't in the database it returns the wrong count it still says 1 record found when it should say 0! I think i starred myself blind at the problem, but i'm not sure! Hope you guys can help me with something that should have been straight forward EDIT: You can try it here: http://johns3n.net/none/classes/ ?slug=forside AND ?slug=underside are both in the database so there the count returned should be 1 if you use those, but using i.e ?slug=randomthing still returns 1 on the screen. Link to comment https://forums.phpfreaks.com/topic/260075-mysql-returns-wrong-number-of-rows-from-_get-value/ Share on other sites More sharing options...
Johns3n Posted March 31, 2012 Author Share Posted March 31, 2012 Solved this myself should have used mysql_num_rows($result); instead of count($result); =) Link to comment https://forums.phpfreaks.com/topic/260075-mysql-returns-wrong-number-of-rows-from-_get-value/#findComment-1333030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.