1
我想顯示信息從我的Wordpress插件(代碼如下)中創建的表中,我可以顯示在表中沒有任何問題,但我無法計算了解如何以某種排序順序顯示IE按行ID排序。如何get_results從數據庫和顯示在表中排序
<?php
echo "<table class='widefat'>"; // start a table in HTML
echo "<thead>
<tr>
<th>Select</th>
<th>Id</th>
<th>Serial Number</th>
<th>UserID</th>
<th>Owner</th>
<th>Name</th>
<th>AreaCode</th>
<th>Number</th>
<th></th>
</tr>
</thead>
<tfoot>
<tr>
<th>Select</th>
<th>Id</th>
<th>Serial Number</th>
<th>UserID</th>
<th>Owner</th>
<th>Name</th>
<th>Area Code</th>
<th>Number</th>
<th></th>
</tr>
</tfoot>
<tbody>";
$result = $wpdb ->get_results("SELECT * FROM wp_new_table ");
foreach($result as $row){
echo "<tr><td><input name='ID_selected' type='radio' value='" . $row->id. "' /></td><td>" . $row->id. "</td><td>" . $row->sn. "</td><td>" . $row->userid. " </td><td>" . get_user_display_name($row->userid) ."</td><td>" . $row->name. "</td><td>" . $row->areacode. "</td><td>" . $row->phone. "</td><td>
<a href='" . $_SERVER['REQUEST_URI'] . "&dbviewedit=" . $row->id . "'>View/Edit</a></td></tr>";
}
echo "</tbody></table>";
?>
我想通了: - ) $ result = $ wpdb - > get_results(「SELECT * FROM wp_new_table」); 變成 $ result = $ wpdb - > get_results(「SELECT * FROM wp_new_table ORDER BY id DESC」); 然後,我剛剛發現約翰史密斯的答案!謝了哥們! – Josh