我有一个库存表,可以使用每个事务进行更新。目前有4种产品,但在某些时候可能会有更多。以下是我用来拉动所有内容的表格。
<?php
$db = new mysqli('', '', '', 'inventory');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = "SELECT * FROM inventory";
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
echo "<table style='border: 2px;font-family: tahoma;'><caption><b>Entire Database Contents</b></caption><tr><td>ID</td><td>Time Stamp</td><td>Staff</td><td>Client</td><td>Needed</td><td>Product</td><td>Amount</td><td>Totals</td><td style='width: 200px;'>Comments</td></tr>";
while($row = $result->fetch_assoc()){
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['timeStamp'] . '</td>';
echo '<td>' . $row['staff'] . '</td>';
echo '<td>' . $row['client'] . '</td>';
echo '<td>' . $row['dateNeeded'] . '</td>';
echo '<td>' . $row['product'] . '</td>';
echo '<td>' . $row['amt'] . '</td>';
echo '<td>' . $row['tot'] . '</td>';
echo '<td>' . $row['comments'] . '</td></tr>';
}
echo "</table>";
?>
我想做的是仅提取每种产品的最新条目。我想也许DISTINCT和LAST可能在这里发挥作用,但不知道如何设置它。有什么指针吗?
答案 0 :(得分:1)
您应该创建date_added字段并按其排序:
$sql = "SELECT * FROM inventory ORDER BY date_added DESC";
答案 1 :(得分:1)
您只需选择@TargetApi(Build.VERSION_CODES.KITKAT)
private void enableRemoteDebugging() {
try {
WebView.setWebContentsDebuggingEnabled(true);
} catch (IllegalArgumentException e) {
LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
e.printStackTrace();
}
}
时间戳:
MAX
答案 2 :(得分:0)
这应该有效:
select distinct product, id, timeStamp, staff, client, dateNeeded, amt, tot, comments from inventory order by timestamp desc;