php - Add current date to dropdown if doesn't exist in database -


i have table date selector trying add current date option unless there rows present date.

here how looks:

enter image description here

today 25th yet shows date 20th since there rows present 07/20/2013 date in it. how shows current date?

here code

<div class="lookup"> <form action="index.php" method="get"> <select name="exam_date" onchange="location = this.options[this.selectedindex].value;" id="type" class="neutral"> <?php $sql_gdate    = "select distinct pat_date patients order pat_date desc"; $result_gdate = mysql_query($sql_gdate); while ($row_gdate = mysql_fetch_assoc($result_gdate)) {     echo '<option value="?exam_date=' . $row_gdate['pat_date'] . '"';     if ($exam_date == $row_gdate['pat_date']) {         echo 'selected="selected"';     } else {         echo '';     }     echo '>' . $row_gdate['pat_date'] . '</option>'; } ?> </select> </form>  </div> 

you can use following sql modify table dates stored -

alter table patients     add column pat_date_new date not null; update patients set pat_date_new = str_to_date(pat_date,'%m/%d/%y'); -- check values stored correctly before dropping old column  alter table patients     drop column pat_date,     change column pat_date_new pat_date date not null; 

once dates stored in correct format able use query posted -

select distinct pat_date patients union select current_date order pat_date desc 

you need change format of date received form datepicker. can in either php or sql -

insert `patients` (`pat_date`) values(str_to_date('07/25/2013','%m/%d/%y')); 

note: should not using deprecated mysql_* functions. use either mysqli_* or pdo.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -