2011-09-02 141 views
0

我有一個PHP表單,其中SQL表中的一個字段顯示爲鏈接。不過,我希望它顯示除字段數據以外的內容,並且只有在該字段中有內容時才顯示。 這是一個演出列表,我想顯示一個鏈接到'setlist'的選項。我不希望它像現在這樣顯示文件名,而是一個圖像圖標或類似'SET'的東西。IF語句導致Catch錯誤消息

有人建議我加

if ($row['gigsetlist']=="") { 

的代碼,但是這已經拋出了一個意外的捕捉..錯誤消息。

下面是包含上述if語句的代碼。 有人可以指出還有什麼可能會丟失或衝突?

<?php 

try { 

    require_once "pdo_testdb_connect.php"; 

    $dbh = testdb_connect(); 

    $sql = "SELECT id, gigdate, date_format(gigdate,'%d %M') as d, gigshortdesc, 
    gigsetlist FROM gigs WHERE gigdate 
    BETWEEN '1995-01-01' AND '1995-12-31' ORDER BY gigdate ASC"; 

    print '<table>'; 

    foreach($dbh->query($sql) as $row) 
    { 
     print '<tr> 
     <td width=100>' . $row['d'] . ' </td> 
     <td> ' . $row['gigshortdesc'] . '</td> 
     <td>'; 
     if ($row['gigsetlist']=="") 
     { 
      print '<a href="sets/' . $row['gigsetlist'] . '.php" 
      onclick="return openWin (this.href, 

      this.target, 480, 480, 1, 0, 0, 0, 0, 1);" 
      rel="nofollow" target="_setlist">' . $row['gigsetlist'] . '</a></td> 
      </tr>'; 
     } 

    } 

    print '</table>'; 

    $dbh = null; 

} 

catch(PDOException $e) 
{ 
    echo $e->getMessage() 
;}?> 

非常感謝

+3

我不知道它是否錯誤地發生,但你忘了一個結尾'}'。我格式化你的代碼並插入缺少的'}'。除此之外,if語句對我來說沒有意義。你不是指'if($ row ['gigsetlist']!=「」)'? –

+0

謝謝Sascha。是的,這是我忽略的!如你指出的那樣,你也會誤入歧途。非常感謝。它現在工作得很好。 –

回答

0

變化

來源:

if ($row['gigsetlist']=="") 

要:

if ($row['gigsetlist']!="") 

你必須檢查$行[ 'gigsetlist']不等於這意味着它包含一些dat然後顯示鏈接。

+0

謝謝@Satish,已經出色地工作。當然,應該已經發現了。非常感謝 –