2015-01-16 37 views
0

希望有人能幫助我解決這個小問題。 我想在我的後端頁面中回顯我的MySQL中的tinyint,看看誰接受了,誰不接受。回覆tinyint在WordPress管理頁面

這是我的代碼:

<?php 
ini_set("display_errors", true); 
error_reporting(E_ALL); 
global $wpdb; 

$result2 = $wpdb->get_results("SELECT * FROM ReparationQuotes ORDER BY Id DESC", OBJECT); 
?> 

<?php foreach ($result2 as $q2) { 
    //$quote2 = $wpdb->get_results("SELECT Accepted FROM ReparationQuotes Where ReparationId = '" . esc_sql($q2->Id) . "'", OBJECT); 
    if ($q2->Accepted == 1) 
    $accepted = "true"; 
    elseif ($q2->Accepted == 0) 
    $accepted = "false"; 
} 
    ?> 

然後我試圖打電話給變量在我的表

<td class="post-title page-title column title"> 
     <strong> <?php echo $accepted ?> </strong> 
    </td> 

不幸這只是把「假」。沒有找到真正的地方。 它似乎是從MySQL獲取錯誤的值。

如果我將1更改爲0並將0更改爲1,則所有內容均爲「true」。 這裏可能是什麼問題? 謝謝大家的幫忙。

回答

0

好吧,我編輯了我的PHP,它帶來了0和1似乎有必要的地方。 未填充的tinyint元素將回顯「Geen offerte」。

這是我的結果:

<?php 
ini_set("display_errors", true); 
error_reporting(E_ALL); 
global $wpdb; 

$result = $wpdb->get_results("SELECT * FROM Reparation ORDER BY Id DESC", OBJECT); 
$result2 = $wpdb->get_results("SELECT * FROM ReparationQuotes ORDER BY ReparationId DESC", OBJECT); 
?> 

<?php 
if(count($result) > 0) { 

    foreach($result as $rep) { 

     $quote = $wpdb->get_results("SELECT COUNT(Id) as total FROM ReparationQuotes WHERE ReparationId = '" . esc_sql($rep->Id) . "'", OBJECT); 

     foreach ($result2 as $q2) { 
     $quote2 = $wpdb->get_results("SELECT Accepted FROM ReparationQuotes Where ReparationId = '" . esc_sql($rep->Id) ."'", OBJECT); 
    } 
     ?> 

,然後輸出的文件是這樣的:

<td class="post-title page-title column title"> 
      <strong><?php if ($quote2) : ?> 
      <?php echo $quote2[0]->Accepted; ?>      
      <?php else: ?> 
    <p style="background-color: gray;">Geen offerte</p> 
<?php endif; ?> </strong> 
     </td> 

我打開了另一個問題爲編輯在這段代碼,因爲不是一切似乎都在上班的路上我想要它,但至少在此之前這是個訣竅。