I use this code to display data from MySQL table in html, but I need the ability to create html tables that will display records added in the last day / week / month.
Here is what I have so far:
<?php
$db_host = 'localhost';
$db_name = 'DB';
$db_username = 'NAME';
$db_password = 'PASS';
$db_table_to_show = 'TABLE';
$connect_to_db = mysql_connect($db_host, $db_username, $db_password)
or die("Could not connect: " . mysql_error());
mysql_select_db($db_name, $connect_to_db)
or die("Could not select DB: " . mysql_error());
mysql_set_charset("utf8");
$qr_result = mysql_query("select * from " . $db_table_to_show)
or die(mysql_error());
echo '<table id="table">';
echo '<thead>';
echo '<tr>';
echo '<th class="table-fandom">fandom</th>';
echo '<th>author</th>';
echo '<th class="table-name">name</th>';
echo '<th>size</th>';
echo '<th class="table-status">status</th>';
echo '<th>date</th>';
echo '<th>tags</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
while($data = mysql_fetch_array($qr_result)){
echo '<tr>';
echo '<td>' . $data['fandom'] . '</td>';
echo '<td>' . $data['author'] . '</td>';
echo '<td><a href="/goto/' . $data['url'] . '" target="_blank">' . $data['name'] . '</a><div class="menu" style="display: none;"><br> ' . $data['annotation'] . ' </div></td>';
echo '<td>' . $data['size'] . '</td>';
echo '<td>' . $data['status'] . '</td>';
echo '<td>' . $data['date'] . '</td>';
echo '<td>' . $data['tags'] . '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
mysql_close($connect_to_db);
?>
PS Sorry for my english, it's not my native language.
if i got it true you want to show data that added for specific date/time or between date/time ranges. you should use mysql query to get data that for example last day added. you should change query:
$qr_result = mysql_query("select * from " . $db_table_to_show)
first you should save date/time for each row when it added or updated. after that you can get today date/time by PHP functions and then use it in your query. an example:
SELECT * FROM [TableName] WHERE `AddedDate` BETWEEN "2012-03-15" AND "2012-03-31";
PHP function to get date : http://php.net/manual/en/function.getdate.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.