Jump to content

select where date column - today?


flemingmike

Recommended Posts

is it possible to do something like

 

$today = date("Y-m-d");

$result = mysql_query("SELECT * FROM staff where date = '.$today.'  ");

 

also, is it normal for the first entry in the database not to be displayed?  i have 6 entries in a table and only 2-6 are shown.  when i changed the id for 1 to 7, it only displayed 3-7.

Link to comment
https://forums.phpfreaks.com/topic/213791-select-where-date-column-today/
Share on other sites

ok, so i got it to display just records with todays date.  it still isnt displaying the first record though.

 

$result = mysql_query("SELECT * FROM staff WHERE date >= '".date('Y-m-d').' 00:00:00'."' AND date < '".date('Y-m-d').' 23:59:59'."' ");
while($row = mysql_fetch_array($result))
  {


echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Job Number</th>
<th>Date</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row["ID"] . "</td>";
  echo "<td>" . $row["Name"] . "</td>";
  echo "<td>" . $row["jobNO"] . "</td>";
  echo "<td>" . $row["Date"] . "</td>";
  echo "</tr>";
  }
echo "</table>";




  }

You should remove it altogether.

 

if ($result = mysql_query("SELECT * FROM staff WHERE date >= '".date('Y-m-d').' 00:00:00'."' AND date < '".date('Y-m-d').' 23:59:59'."' ") {
  if (mysql_num_rows($result)) {
    echo "<table border='1'>
    <tr>
    <th>ID</th>
    <th>Name</th>
    <th>Job Number</th>
    <th>Date</th>
    </tr>";
    while ($row = mysql_fetch_array($result)) {
      echo "<tr>";
      echo "<td>" . $row["ID"] . "</td>";
      echo "<td>" . $row["Name"] . "</td>";
      echo "<td>" . $row["jobNO"] . "</td>";
      echo "<td>" . $row["Date"] . "</td>";
      echo "</tr>";
    }
    echo "</table>";
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.