how to solve date matching in php mysql website? -
so here thing dates users select tags this:
<select> <?php for($i=date('m'); $i>=0; $i--){ echo "<option>".$i."</option>"; } ?> </select>
now give 05 first option 4,3,2,1 next options, want 04,03,02,01 options.
how can that?
also running sql query deletes rows matching dates.
so date selected user comes 2013-5-18
(without zero) date in database 2013-05-18
(with zero), dates don't match , query unable delete row.
also can change way date stored in database?
i store date 2013-5-18
(without zero) , automatically gets stores 2013-05-18
(with zero).
any other thing me match dates can run delete query?
try:
echo "< option>".sprintf("%02d", $i)."< /option>";
sprintf format number have preceding 0 when required.
what you're seeing date('m')
returning value 05 first month. when add 1 ($i++
) it's being cast integer, next value 6. might presume actual code uses $i--
, presently looks lot infinite loop.
you might consider handling formatting when build query, rather on form presentation. $month = sprintf("%02d", $_post['month']);
rather relying on client pass forward nicely.
Comments
Post a Comment