2017-03-03 48 views
0

如何在此代碼中設置顯示類似「目前沒有發佈內容,請稍後再回來查看」的條件。如果沒有任何檢索或輸入?目前,如果沒有檢索到或輸入任何內容,它只在前端顯示任何內容。因此,我想代之以放棄一切信息。How to say如果沒有檢索到或已輸入數據,請執行此操作

if($seasontype=="pending"){ 

$result = " SELECT * FROM ".$wpdb->prefix."bidsys_picklist WHERE sport = ".$sport." AND pick_result='PENDING' ORDER BY game_date DESC"; 
$newmeta = $wpdb->get_results($result); 

$resultvals = ""; 
foreach($newmeta as $data){ 

    $game_details=""; 
    $hometeam = ""; 
    $visitorteam = ""; 

    if(trim($data->game_details)!="") 
    $game_details = $data->game_details; 

    if($data->visitorteam!=""){ $visitorteam = "<br /><strong>Visitor Team:&nbsp </strong>".$data->visitorteam.""; } 
    if($data->hometeam!=""){ $hometeam = "<br /><strong>Home Team:&nbsp </strong>".$data->hometeam.""; } 

$gamedate = strtotime($data->game_date); 
$gametime = $data->game_time; 
$endtime = strtotime('+30 minute',$gametime); 
$nowtime = date('Y-m-d h:i:s'); 

    $resultvals = $resultvals."<table class='inner_result'> 
       <tr class='hdr_3'> 
       <td colspan='4' >".date("n-d-Y",$gamedate)."<br /> 
       ".$gametime." 
       ".$hometeam." 
       ".$visitorteam." 
       <br /><div class='todays_pick' ><span><strong>Pick:</strong></span>&nbsp ".$data->your_pick."<br /><span><strong>Odds:</strong></span>&nbsp ".$data->pick_odds." </div> 
       <br /> ".$game_details."</td> 
       <td><br />Recommended Unit Play (Risk)<br /> 
       <div class='todays_units' >".$data->units_play." Units</div> 
       </td> 
       </tr> 
       <tr> 
       </tr> 
       </table>"; 
} 

echo $resultvals; 
} 

回答

2
if (empty($resultvals)) { 
    echo 'There are no results'; 
} 
+0

真棒謝謝! – kma1289

0

行獲取數退還,並檢查是否行是大於0

if($wpdb->num_rows>0){ 
     echo "Your all posts"; 
    }else{ 
     echo "Nothing posted"; 
    } 
相關問題