我使用foreach loop
顯示wp_share表中的一些數據。我正在嘗試的是,如果沒有數據,那麼它會顯示msg,如「找不到數據」,如果找到,則會轉到循環。WordPress查詢查詢中的空數據
以下代碼我寫了,但它總是獲取空值,但實際上有數據。
<?php
$me=$current_user->user_login;
$retrieve_data = $wpdb->get_results("SELECT * FROM wp_share where Status='onsell' and user!='$me'");
echo '<table border=0 class="table">
<tr> <th colspan="5" style="color:blue;border-bottom:2px solid blue;"> Purchase share from user offer</th> </tr>
<tr><th>OfferBy</th><th>OfferValue</th><th>Qnty</th> <th> ref</th> <th> action</th></tr>';
if (mysql_num_rows($retrieve_data)<=0) {
echo '<tr><td style="color:crimson;">' ."there is no data found". '</td>';
}
else{
foreach ($retrieve_data as $retrieved_data){
echo '<tr><td>'. $retrieved_data->user.'</td>';
echo '<td>'.$retrieved_data->offervalue.'</td>';
echo '<td>'. $retrieved_data->user.'</td>';
echo '<td>'. $retrieved_data->id.'</td>';
}
?>
您好我道歉,其實我想批准您的變化,但沒有發現任何選項如何做到這一點thnks。 – Mithu
它已經完成了,你可以看到[修訂歷史記錄](https://stackoverflow.com/posts/46314128/revisions)。擁有超過2,000個信譽點的社區成員會自動批准修改。 – halfer