Hello all, I am trying to query my db based on a job_id that i get from the url, then if it exists in the db display the page, otherwise display a message. It will basically stop the page having blank details if the job does not exist. I have this which is what I want to do. <? $q = "select job_id from job_post; $w = mysql_query($q) or die(mysql_error()); $e = mysql_fetch_array($w); if ($_GET[job_id] is not in $e) //this is the bit i need help with :) { Sorry that job does not exist. } else { show the page normally } ?> Code (markup):
You've completely missed taking the ID from the GET values and doing the WHERE in the query. You are pulling ALL the data and then check against the GET. That's wasting a lot of bandwidth. Query ONLY what you need and then count num rows.
$jobid=mysql_escape_string($_GET(jobid)); $q = "select job_id from job_post where job_id='$jobid'"; $w = mysql_query($q) or die(mysql_error()); if (!mysql_num_rows($w)) echo "not in db"; else { $e = mysql_fetch_array($w); //show details } Code (markup):