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! Link to comment https://forums.phpfreaks.com/topic/33678-check-if-id-exists/ 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] Link to comment https://forums.phpfreaks.com/topic/33678-check-if-id-exists/#findComment-157836 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] Link to comment https://forums.phpfreaks.com/topic/33678-check-if-id-exists/#findComment-157837 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... Link to comment https://forums.phpfreaks.com/topic/33678-check-if-id-exists/#findComment-157843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.