Fanatic Posted October 24, 2012 Share Posted October 24, 2012 How can I in PHP check if a MySQL row exist? and then return true or false? I tried this: // Does a game with that url-name exist? public function nameExist() { return $this->db->execute('SELECT COUNT(*) FROM `main_games` WHERE `url`=?', array($this->getSubdomain())); } Here is the source of the class: http://pastebin.com/p17gUEPA And here is the source of the hook where I run this class from: http://pastebin.com/WjSNLCMd Hope someone might be able to help me figure this out. Quote Link to comment Share on other sites More sharing options...
Zettieee Posted October 24, 2012 Share Posted October 24, 2012 ermmm... try like this: <?php $checker = mysql_query('SELECT * FROM `main_games` WHERE `url`=?', array($this->getSubdomain())); $run = mysql_num_rows($checker); if ($run){ echo' they is a game in that url'; exit(); } else { echo' no game sorry'; } ?> Don't know if that's how you want it, but that's somewhat how I do it :) Quote Link to comment Share on other sites More sharing options...
Djkanna Posted October 25, 2012 Share Posted October 25, 2012 How can I in PHP check if a MySQL row exist? and then return true or false? I tried this: // Does a game with that url-name exist? public function nameExist() { return $this->db->execute('SELECT COUNT(*) FROM `main_games` WHERE `url`=?', array($this->getSubdomain())); } Here is the source of the class: http://pastebin.com/p17gUEPA And here is the source of the hook where I run this class from: http://pastebin.com/WjSNLCMd Hope someone might be able to help me figure this out. With ezRPG, there's db->numRows($result); execute() returns the result, if the query doesn't fail. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.