Pregunta

I have run into a bit of a rut... I have individual dates saved in my database. I am outputting them for editing and I need to be able to only select an individual day (ex. Wednesday) or various days (ex. Thursdays and Fridays) and filter them in my output. I have never done this before and have no idea how to do it. I am outputting the dates in a simple while loop from the DB:

$today = date("Y-m-d");
$getRates = mysql_query("SELECT * FROM rates WHERE hotel_id = '$hotelId' AND contract_id = '$contractId' AND room_id='$roomId' AND DATE(booking_date) >= '$today'") or die(mysql_error());
while($room = mysql_fetch_array($getRates)){
    $bdat = $room['booking_date'];
    $bdate = date('m/d/Y', strtotime($bdat));
    echo "<tr><td><input type='checkbox' name='date' value='$bdate' checked='checked' /></td>";
    echo "<td>$bdate</td>";
    echo "</tr>";
    }}

And this is my filter:

<input type="checkbox" value="1" checked="checked" name="Monday" />Lunes
<input type="checkbox" value="2" checked="checked" name="Tuesday" />Martes
<input type="checkbox" value="3" checked="checked" name="Wednesday" />Miercoles
<input type="checkbox" value="4" checked="checked" name="Thursday"/>Jueves
<input type="checkbox" value="5" checked="checked" name="Friday"/>Viernes
<input type="checkbox" value="6" checked="checked" name="Saturday"/>Sabado
<input type="checkbox" value="7" checked="checked" name="Sunday"/>Domingo
<input type="submit" name="filter" value="Filtar Dias" />

Any help on this subject would be soooooo greatly appreciated. I really have no idea how to go about doing this. Thank you in advance!

¿Fue útil?

Solución

One option might be to use the dayname function:

SELECT * FROM table_name WHERE DAYNAME(yourdatecolumn) = 'Tuesday';

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_dayname

Otros consejos

    SELECT * FROM mytable WHERE DAYOFWEEK(some_event_date) = 7;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top