0

我无法指定我希望输出的数据,我想做的是打印配方表中包含的所有配方标题。

$stid2 = oci_parse($conn, 'select recipetitle from recipes.recipe');
oci_execute($stid2);

while ($row = oci_fetch_array($stid2, OCI_ASSOC)) {
  echo "<p>Sorry, there are no titles</p>";
    } else {
        echo '<p> <b>Recipe Title: </b>' . $row['recipetitle'] . '</p>';
    }
}

这甚至可能吗?我只是收到“未识别的索引”错误。

谢谢

4

1 回答 1

0

As I commented, while / else doesn't exist in php.

Instead, try :

$stid2 = oci_parse($conn, 'SELECT `recipetitle` FROM `recipes`.`recipe`');
oci_execute($stid2);

//Output var
$output = '';

while ($row = oci_fetch_array($stid2, OCI_ASSOC)) {
    $output .= '<p> <b>Recipe Title: </b>' . $row['recipetitle'] . '</p><br>';
}

//Ternary test
$output == '' ? echo "<p>Sorry, there are no titles</p>" : echo $output;
于 2013-03-11T08:04:22.143 回答