這看起來像一個非常簡單的問題,但它讓我難住了大聲笑。我試圖打印從數據庫收到的行。我想將行存儲在數組中,然後使用for循環打印它們。我知道查詢可以工作,但是當我嘗試打印數組元素時,它只打印字數組。我已經厭倦了使用foreach循環和簡單的for循環。如果任何人都能指出我正確的方向,那將是一種拯救生命的方式。PHP用於循環打印陣列
印刷PHP代碼
<?php
$type = "FREE";
$free = getTerms($type);
echo "<p>";
for($j = 0; $j < count($free); $j++)
{
echo "start".$free[$j]."end";
}
echo "</p>";
?>
從數據庫
function getTerms($type)
{
$terms = array();
$connection = mysql_open();
$query = "select terms from terms_and_con where accountType='$type' && currentTerms='YES'";
$results = mysql_query($query, $connection) or show_error("signUp.php", "", "");
while($row = mysql_fetch_array($results))
{
$terms[] = $row;
}
mysql_close($connection) or show_error("signUp.php", "", "");
return $terms;
}
三江源這麼多,你固定它 – Richard
+1要注意,只是因爲你只從MySQL中選擇一個值,並不意味着它只返回那個元素,它仍然是一個數組中的key =>值對。 – animuson
+1我以爲他想打印數組,只是查詢中的術語值。 – ace