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'; Link to comment https://forums.phpfreaks.com/topic/138126-simple-solution/ 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"); } Link to comment https://forums.phpfreaks.com/topic/138126-simple-solution/#findComment-722050 Share on other sites More sharing options...
dreamwest Posted December 23, 2008 Author Share Posted December 23, 2008 thanks Link to comment https://forums.phpfreaks.com/topic/138126-simple-solution/#findComment-722051 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; } Link to comment https://forums.phpfreaks.com/topic/138126-simple-solution/#findComment-722052 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. Link to comment https://forums.phpfreaks.com/topic/138126-simple-solution/#findComment-722054 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 Link to comment https://forums.phpfreaks.com/topic/138126-simple-solution/#findComment-722068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.