TheFilmGod Posted December 30, 2007 Share Posted December 30, 2007 I would like to create a php conditional. If not null do this... Something like this: if ( $a1 not null ) { .... ......................................... if ($you answered this) { echo "You are the php master"; } Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 30, 2007 Share Posted December 30, 2007 If $a1 only exists if they are php master you could use this: if(isset($a1)){ echo "you are the php master"; } Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 30, 2007 Share Posted December 30, 2007 Assuming you are doing a quizzy type thing (good technical language there ), which you may not be. Not Null wouldn't be right because they could answer with anything that isn't nothing and thus get it correct Say the answer the $a1 was 42 (who knows the question? =P) then you'd do: if ($a1 == 42) { echo "You are the php master!!"; } else { echo "Unfortunately you got that one wrong.."; } Or if the answer was forty two (word form/textual answer): if ($a1 == "forty two") { echo "You are the php master!!"; } else { echo "Unfortunately you got that one wrong.."; } Hope that helps? Sam Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted December 30, 2007 Author Share Posted December 30, 2007 thanks for the feedback! The program will always assign something to a variable. If there isn't anything to assign, the program will assign null. I need to check if it is null or not. Is there a php statement to do that? Quote Link to comment Share on other sites More sharing options...
Sesquipedalian Posted December 30, 2007 Share Posted December 30, 2007 yeah.. if ($var == NULL) { } put what you want if the variable is null in the brackets ({ }) but if your checking that its not null.. then just do: if ($var !== NULL) { } Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted December 30, 2007 Author Share Posted December 30, 2007 The previous reply is really good but... in front of me I have a php book that gives me a set of different functions to check if it's null. Won't the function isset() work too? What about is_null(), or empty()? Which is the best in this situation. They all seem to do the same thing in my situation. Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 do you mean this concept.... <?php $word="redarrow"; if($word=="redarrow"){ $x="correct"; }else{ $x="incorrect"; } echo $x; ?> Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted December 30, 2007 Author Share Posted December 30, 2007 thanks for all the help! I'm going to try isset() in my code. If it works I click "solved" otherwise I'll be back! See you later php masters! Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 isset is when a varable holds anythink or has been set... $redarrow=""; << isset beleve or not..... $redarrow="$redarrow"; << isset defently..... $redarrow << not set no = or " " condition Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted December 30, 2007 Author Share Posted December 30, 2007 isset is when a varable holds anythink or has been set... $redarrow=""; << isset beleve or not..... $redarrow="$redarrow"; << isset defently..... $redarrow << not set no = or " " condition Yes I realize this. I pull my data out of mysql. If there isn't anything there the php code pulls out "NULL". Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 30, 2007 Share Posted December 30, 2007 correct same as: $redarrow // not set nothink there NULL $redarrow=" "; //set but NULL nothink set to Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted December 30, 2007 Author Share Posted December 30, 2007 Thanks for everyone's help. I ended up using isset () and had to make sure that the default value in mysql was NULL to make it work! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.