1 回答

TA貢獻1816條經驗 獲得超6個贊
不是啟動和停止 PHP 代碼,而是簡單地回顯要包含的 HTML 代碼嗎?它可能會幫助您組織您想要在循環中重復的內容以及您不想重復的內容。這是一個例子:
$myArray = []; //array that will hold the values you get from database for later use
$sql_client = "SELECT * FROM clienti WHERE nume = ? LIMIT 1";
$stmt_client = $conn->prepare($sql_client);
$stmt_client->bind_param("s", $nume);
$stmt_client->execute();
$result_client = $stmt_client->get_result();
echo '<table>'; //does not repeat
while($row = $result_client->fetch_row())
{
array_push($myArray, $row); //add each row to an array outside the scope of your loop
echo '<tr>'; //repeats once for each table row
foreach($row as $columnValue){
echo '<td><p>'.$columnValue.'</p></td>'; //repeats for every value in table
}
echo '</tr>';
}
echo '</table>'; //does not repeat
echo $myArray[0][0]; //echo first value of first row
- 1 回答
- 0 關注
- 143 瀏覽
添加回答
舉報