redarrow Posted January 22, 2009 Share Posted January 22, 2009 advance thank you. my if($month==$i wont let the month off january go red why please cheers. <?php echo " <html> <head> <title> my month</title> </head> <body>"; $month=array(1=>"january","febuary","march","april","may","june","july","august","september", "october","november","december"); $today=time(); $f_today=date("d-M-Y",$today); $g_month=date("n",$today); echo "<br><br> Today is $f_today <br><br>"; echo " <form method='POST' method=' '>"; echo"<select name='month'>"; for($i=1; $i<=12; $i++){ echo"<option value='$i'>"; if($month==$i){ $month="<font color='red'>$month</font>"; } echo "{$month[$i]}</option>"; } echo "<form> </body> </html>"; ?> Link to comment https://forums.phpfreaks.com/topic/141943-month-color-problam-code-included/ Share on other sites More sharing options...
printf Posted January 22, 2009 Share Posted January 22, 2009 this... if($month==$i){ should be if($month[$i]==$i){ Link to comment https://forums.phpfreaks.com/topic/141943-month-color-problam-code-included/#findComment-743253 Share on other sites More sharing options...
redarrow Posted January 22, 2009 Author Share Posted January 22, 2009 Still does not make the month off January red in the select box of months mate cheers. I want the current month off January, the color red cheers... current code <?php echo " <html> <head> <title> my month</title> </head> <body>"; $month=array(1=>"january","febuary","march","april","may","june","july","august","september", "october","november","december"); $today=time(); $f_today=date("d-M-Y",$today); $g_month=date("n",$today); echo "<br><br> Today is $f_today <br><br>"; echo " <form method='POST' method=' '>"; echo"<select name='month'>"; for($i=1; $i<=12; $i++){ echo"<option value='$i'>"; if($month[$i]==$i){ $month="<font color='red'>$month</font>"; } echo "{$month[$i]}</option>"; } echo "</form> </body> </html>"; ?> Link to comment https://forums.phpfreaks.com/topic/141943-month-color-problam-code-included/#findComment-743255 Share on other sites More sharing options...
dvd420 Posted January 22, 2009 Share Posted January 22, 2009 if($month[$i]==$i) Should it work?? Comparing string with integer, it'll always return false. The following can be a valid one: if($month[$i] == $g_month) Link to comment https://forums.phpfreaks.com/topic/141943-month-color-problam-code-included/#findComment-743268 Share on other sites More sharing options...
printf Posted January 22, 2009 Share Posted January 22, 2009 if($month[$i]==$i) Should it work?? Comparing string with integer, it'll always return false. The following can be a valid one: if($month[$i] == $g_month) You're 100% right, my bad! if($i == $g_month) Link to comment https://forums.phpfreaks.com/topic/141943-month-color-problam-code-included/#findComment-743278 Share on other sites More sharing options...
redarrow Posted January 22, 2009 Author Share Posted January 22, 2009 still got no color any reason mate? <?php echo " <html> <head> <title> my month</title> </head> <body>"; $month=array(1=>"january","febuary","march","april","may","june","july","august","september", "october","november","december"); $today=time(); $f_today=date("d-M-Y",$today); $g_month=date("n",$today); echo "<br><br> Today is $f_today <br><br>"; echo " <form method='POST' method=' '>"; echo"<select name='month'>"; for($i=1; $i<=12; $i++){ echo"<option value='$i'>"; if($month[$i] == $g_month) { $month[$i]="<font color='red'>{$month[$i]}</font>"; } echo "{$month[$i]}</option>"; } echo "</form> </body> </html>"; ?> Link to comment https://forums.phpfreaks.com/topic/141943-month-color-problam-code-included/#findComment-743282 Share on other sites More sharing options...
printf Posted January 22, 2009 Share Posted January 22, 2009 See my last post for the right method! Link to comment https://forums.phpfreaks.com/topic/141943-month-color-problam-code-included/#findComment-743284 Share on other sites More sharing options...
dvd420 Posted January 22, 2009 Share Posted January 22, 2009 Hi, the prob is in HTML styling. To get colored options the method is something like: <select> <option style="color:red">Item1</option> <option style="color:green">Item2</option> </select> so now u should use: if($month[$i] == $g_month) { echo "<option value='$i' style=\"color:red\">"; } else { echo "<option value='$i' style=\"color:any_color\">"; } echo "$month[$i] </option>"; Link to comment https://forums.phpfreaks.com/topic/141943-month-color-problam-code-included/#findComment-743288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.