开发者

An IF statement is resulting in a Catch error message

开发者 https://www.devze.com 2023-04-02 12:24 出处:网络
I have a PHP form where one of the fields in the SQL table shows up as a link. However I want it to display something other than the field data and only if that field has something in it.

I have a PHP form where one of the fields in the SQL table shows up as a link. However I want it to display something other than the field data and only if that field has something in it. It's a gig list and I want the option of displaying a link to the 'setlist'. I don't want it to display the filename though as it does now, but an image icon or something like 'SET'.

Someone suggested I add

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

to the code but this has thrown up a Unexpected Catch.. error message.

Below is the code with the above if statement included. Can someone point out what else might be missing or conflicting?

<?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 '<开发者_如何学C;/table>';

    $dbh = null;

}

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

Many thanks


Change

From:

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

To:

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

You have to check $row['gigsetlist'] not equal to empty which means it contains some data then display the link.

0

精彩评论

暂无评论...
验证码 换一张
取 消