I'm trying to make an If/Else option in the case a database query comes back with nothing. But when I use the code included below, it always comes back saying there is no result.
I'm guessing it's because it's asking if there are any results to the query
after it's already finished and the array created.
How can I get it to say basically: If there are no database records fitting
the query, then do this...otherwise do this?
Thanks!!
Liam
$query_RS_con = "SELECT * FROM $conTBL WHERE $field = \"$item\"";
$RS_con = @mysql_query($query_RS_con, $connection) or die("Couldn't query:
" . mysql_error());
while ($row_RS_con = mysql_fetch_array($RS_con)) {
$procid = $row_RS_con['uid'];
$procid2 = $row_RS_con['id'];
$procpass = $row_RS_con['cont_password'];
}
if (!($row_RS_con)) {
$statusmsg = "Your Username was not found. Please go back and try
again.<br><br><A HREF='javascript:history.go(-1)'>Click Here to go back and
try again.</a><br>(You may need to click the ACCESS menu option
twice.)<br>";
} else {
if (($pass1) == ($procpass)) {
header("Location:
http://www.url.org/contact/change.php?uid=$procid$procid2");
} else {
$statusmsg = "Your Password did not match your Username. Please go back
and try again.<br><br><A HREF='javascript:history.go(-1)'>Click Here to go
back and try again.</a><br>(You may need to click the ACCESS menu option
twice.)<br>";
}
}
There is a function called mysql_num_rows() , which takes resultID and returns the number of rows. So if this is zero, that means you got an empty set.
You can do something like this:
PHP Code:
if (mysql_num_rows($result) == 0) {
// Your statements for empty set case.
}
else {
// Your statements otherwise.
}
Hi there,
There is a function called mysql_num_rows() , which takes resultID and returns the number of rows. So if this is zero, that means you got an empty set.
--SNIP--
Yes!! That did it! Perfect! Thanks for your help; I appreciate it. =)