我希望有一個簡單的問題,我找不到任何答案,我的問題是完整的。PHP數組到無序列表
我從MySQL返回的數組,看起來像這樣
mysql> select c.comment, d.name, m.ounces from drink d
inner join mix m on m.drinkID = d.ID
inner join cocktail c on m.cocktailID = c.id
where c.id =5;
+----------------------+------------+--------+
| comment | name | ounces |
+----------------------+------------+--------+
| Long Island Iced Tea | Vodka | 0.75 |
| Long Island Iced Tea | Gin | 0.75 |
| Long Island Iced Tea | Rum | 0.75 |
| Long Island Iced Tea | Tequila | 0.75 |
| Long Island Iced Tea | Sour Mix | 2.00 |
| Long Island Iced Tea | Cola | 1.00 |
| Long Island Iced Tea | Triple Sec | 1.00 |
+----------------------+------------+--------+
我試圖讓PHP產生類似下面這樣一個無序列表。
<div class="jumbotron">
<h2>
Long Island
</h2>
<p>
<ul>
<li>0.5 oz Vodka</li>
<li>0.5 oz Rum</li>
<li>0.5 oz Gin</li>
<li>0.5 oz Tequila</li>
<li>0.5 oz Triple Sec</li>
<li>1 oz Sweet and Sour Mix</li>
<li>1 oz cola </li>
</ul>
我是想這樣的:
$ingredient = "select
c.comment, d.name, m.ounces
from drink d
inner join mix m on m.drinkID = d.ID
inner join cocktail c on m.cocktailID = c.id
where c.id = 4";
//print($ingredient);
$result = mysql_query($ingredient);
<?php foreach($result as $results): ?>
<li><? echo $results ?></li>
<?php endforeach; ?>
從這裏:StackOverflow但無法弄清楚,爲什麼我一直從PHP接收HTTP 500錯誤。
任何幫助或指導,將不勝感激!
謝謝!
不要使用'mysql_ *'函數。自v5.5(2013年6月)開始,它們已被棄用,並從v7.0(2015年12月)開始刪除。請使用[** mysqli _ ***](https://secure.php.net/manual/en/book.mysqli.php)或[** PDO **](https://secure.php.net /manual/en/book.pdo.php)與[**準備語句**](https://secure.php.net/manual/en/pdo.prepare.php)和[**綁定參數** ](https://secure.php.net/manual/en/pdostatement.bindparam.php)。 –
通常500是語法錯誤 – clearshot66
謝謝。我正在重複使用另一篇文章的代碼。 mysqli_ *函數是否可以被找到並替換,或者它們是非常不同的? – user31238633