mkosmosports Posted January 11, 2007 Share Posted January 11, 2007 I want php to run and make a quick check to see if an id exists in mysql. This id features as a url parameter.Currently I do by running a query and selecting all of the id's, putting them into an array and running a condition that if the id in the url isnt in that array show an error page. Is there a quicker way of doing this, perhaps without a mysql_query, but using some other mysql function?Thanks! Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted January 11, 2007 Share Posted January 11, 2007 [code]<?php$checkID=mysql_query("SELECT * FROM table WHERE id = '{$_GET['searchID']}'");if (mysql_num_rows($checkID)) {// Id exists}else {// Id doesnt exist}?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 You still need a query but grabbing all rows is rediculous.If the id is contained within the url, use it in your query.[code]<?php $sql = "SELECT id FROM tbl WHERE id = '{$_GET['id']}';"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // id exists. } }?>[/code] Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 11, 2007 Author Share Posted January 11, 2007 Thanks fellas! That makes sense. I gotta start figuring those out... 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.