elite_prodigy Posted May 14, 2008 Share Posted May 14, 2008 I'm using the following code to test if a "site" exists in the database. <?php //... $sql = "SELECT * FROM `sites` WHERE `site`=$site;"; $result = mysql_query($sql,$conn); $rows = mysql_num_rows($result); if($rows > 0){ if($_SESSION['count'] < 1){ $page = "home"; $_SESSION['count'] = $_SESSION['count']++; } } else{ $page = "sign"; } //... ?> The above code does a couple things. It queries the data I need from the database and uses mysql_num_rows() to see if at least one row exists (I'll add a clause later for when more than one row exists) because if there is a row then the site is there. I'm getting the desired result, but a warning is generated when no site exists because mysql_num_rows() returns an error when there is nothing to query. I need to catch the warning so that it is not displayed to the screen. I thinking a try/catch statement but cannot for the life of me think of how to write it. Can anyone help? Quote Link to comment Share on other sites More sharing options...
burnside Posted May 14, 2008 Share Posted May 14, 2008 sum it like : if($rows == 0 ) { echo " No result ";} else { echo " result blahhhhhhhhhh ";} i think that is what your after, Quote Link to comment Share on other sites More sharing options...
trq Posted May 14, 2008 Share Posted May 14, 2008 <?php $sql = "SELECT * FROM `sites` WHERE `site`=$site;"; if ($result = mysql_query($sql,$conn)) { if (mysql_num_rows($result)) { if ($_SESSION['count'] < 1){ $page = "home"; $_SESSION['count'] = $_SESSION['count']++; } } } else { $page = "sign"; } ?> Quote Link to comment Share on other sites More sharing options...
elite_prodigy Posted May 14, 2008 Author Share Posted May 14, 2008 Thank you! Why didn't I think of that? So simple! I really need to think more logically. 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.