MySql php: check if Row exists
Posted
by
Jeff
on Stack Overflow
See other posts from Stack Overflow
or by Jeff
Published on 2012-03-31T05:02:31Z
Indexed on
2012/03/31
5:29 UTC
Read the original article
Hit count: 141
php
This is probably an easy thing to do but I'm an amateur and things just aren't working for me.
I just want to check and see if a row exists where the $lectureName shows. If a row does exist with the $lectureName somewhere in it, I want the function to return "assigned" if not then it should return "available". Here's what I have. I'm fairly sure its a mess. Please help.
function checkLectureStatus($lectureName)
{
$con = connectvar();
mysql_select_db("mydatabase", $con);
$result = mysql_query("SELECT * FROM preditors_assigned WHERE lecture_name='$lectureName'");
while($row = mysql_fetch_array($result));
{
if (!$row[$lectureName] == $lectureName)
{
mysql_close($con);
return "Available";
}
else
{
mysql_close($con);
return "Assigned";
}
}
When I do this everything return available, even when it should return assigned.
© Stack Overflow or respective owner