-1

本当に頭がおかしくなる If ステートメントについて質問があります。正しい解決策が見つからなかったようです。状況を説明させてください。4 つの状況が考えられます。

  1. フィルムなしで
  2. 写真なしで
  3. フィルムはなくても写真はある
  4. 写真はなくても映画はある

もう少し情報がありますが、必要ないかもしれません。 フィールド film および pictures は、データベース内のフィールドです。PHP スクリプトを使用して、フィールドに何かが入力されているかどうかを確認しています。この情報を使用して、ページを作成します。場合によっては、写真や映画などの場所がないこともあります。私が言っていることを理解していただければ幸いです。

これは私のコードです

<?php
    class Artikel{
public function printWholeArticle()
        {
            include ('connection.php');
            $sSql = "SELECT UNIX_TIMESTAMP(datum) as unixDatum, titel, artikel, id, image, video FROM tblArtikels WHERE id = '" . $this->m_sKey."'"; 
            $res = $mysqli -> query($sSql);
            return ($res);
        }
}


$key = $_GET['id']; // I get the key from the url
$oNieuwsArtikel = new Artikel();
$oNieuwsArtikel -> Key = $key;
$vAllNieuwsArtikel = $oNieuwsArtikel -> printWholeArticle();

$artikel = $vAllNieuwsArtikel -> fetch_assoc();


// just a part of my if statement, to let you guys know how I print the data to the screen
if ($artikel['image'] == "")
            {
                echo "<div class='datum'>" . "<div class='day'>" . date('d', $artikel['unixDatum']) . "</div>" . "<div class='month'>" . "/" . date('m',                            $artikel['unixDatum']) . "</div>" . "<div class='year'>" . date('Y', $artikel['unixDatum']) . "</div>" . "</div>";
            echo "<p>" . "<div class='content_wrap_page'>" .  "<div class='artikel_page'>" 
            . "<h1>" . $artikel['titel'] ."</h1>" . $artikel['artikel'] . "</div>" . "</div>" . "</p>";
            }

ありがとう

4

1 に答える 1

1
if (empty($artikel['video']))
{
    // no film code

    if (!empty($artikel['image']))
    {
        // no film but with picture code
    }
}
else if (empty($artikel['image']))
{
    // no picture code

    if (!empty($artikel['video']))
    {
        // no picture but with film code
    }
}

$film と $picture は、データベース クエリから取得した値に設定されます。

于 2012-11-16T23:26:18.140 に答える