dreamwest Posted December 23, 2008 Share Posted December 23, 2008 Im just learning php and wondering what im doin wrong here: $days = '4'; if ($days == '0'); echo 'no days'; else echo '$days'; Quote Link to comment Share on other sites More sharing options...
leequalls Posted December 23, 2008 Share Posted December 23, 2008 Try this: $days = '4'; if ($days == '0') { echo ("no days"); } else { echo ("$days"); } Quote Link to comment Share on other sites More sharing options...
dreamwest Posted December 23, 2008 Author Share Posted December 23, 2008 thanks Quote Link to comment Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 A few things. Firstly, number are not surrounded by quotes within php, that makes them strings. Secondly, variables are not interpolated within single quotes (they are within double). You've also a few minor syntax errors. $days = 4; if ($days == 0) echo 'no days'; else echo $days; ps: I (and most others) prefer to stick to using braces to group blocks of code. $days = 4; if ($days == 0) { echo 'no days'; } else { echo $days; } Quote Link to comment Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 Try this: $days = '4'; if ($days == '0') { echo ("no days"); } else { echo ("$days"); } Sorry but I must comment. That is an absolutely terrible coding style to get into the habit of. Fine for tiny scripts like this, but start writing decent sized applications and all readability is out the window. Quote Link to comment Share on other sites More sharing options...
dreamwest Posted December 23, 2008 Author Share Posted December 23, 2008 Thanks for the help... I want to take it a step further and add ifelse, i feel like im close but still chasing my tail Heres what ive got so far: $days = 2; $hours = 0; $minuets = 4: if ($days == 0) { echo 'Added '.$hours.' hours and '.$minutes.' minuets ago'; } else { echo 'Added '.$days.' Days ago'; } elseif ($hours == 0) { echo 'none'; } else { echo 'Added '.$hours.' Hours ago'; } My goal is to make it so if there is "0" in any of the variables only the variables with 1 or more will display in a message 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.