[SOLVED] Help with (if $variable is empty) statement
Posted: Thu Mar 26, 2009 11:08 am
Hello all,
I run into this a lot in my programming. Doing a Mysql_num_rows to see if there are any result sets but sometimes it just doesn't seem to work.
Here is what I am doing right now:
If it isn't empty, it executes fine but when it is empty, it doesn't echo anything so my other code doesn't execute.
I've tried this too:
And I've even tried:
What am I missing or not understanding here? Can anyone help me get this to work?
The code is checking to see if a member has reserved tickets. If they haven't, it executes a INSERT INTO SQL statement. If they have, it executes an UPDATE SQL statement. Right now the update portion works perfectly but I can't get it to test for an empty result set.
I really do run into this a lot so if I could find out the best way to do this kind of check, I would be very grateful.
I run into this a lot in my programming. Doing a Mysql_num_rows to see if there are any result sets but sometimes it just doesn't seem to work.
Here is what I am doing right now:
Code: Select all
$ticketsql="SELECT * FROM `ticket_sales` WHERE `show_id`=$showid AND `mid`=$userid";
$ticketresult=mysql_query($ticketsql);
$tickettotalpull = mysql_num_rows($ticketresult);
/*Create a new entry for them*/
if (empty($tickettotalpull)){
echo "empty";
}else{
echo "not empty";
}I've tried this too:
Code: Select all
$ticketsql="SELECT * FROM `ticket_sales` WHERE `show_id`=$showid AND `mid`=$userid";
$ticketresult=mysql_query($ticketsql);
$tickettotalpull = mysql_num_rows($ticketresult);
if ($tickettotalpull == 0){
echo "empty";
}else{
echo "not empty";
}Code: Select all
if ($tickettotalpull !=0){
The code is checking to see if a member has reserved tickets. If they haven't, it executes a INSERT INTO SQL statement. If they have, it executes an UPDATE SQL statement. Right now the update portion works perfectly but I can't get it to test for an empty result set.
I really do run into this a lot so if I could find out the best way to do this kind of check, I would be very grateful.