我想要一个 SQL Select 语句,它从数据库中获取值,如果有任何结果,那么在下拉菜单中显示一个表单和结果。
目前,它获取值,但表单回显有结果的次数。例如,如果查询有 1 个结果,它会回显表单一次。2 结果,回显格式两次,以此类推。我希望表单显示一次,但下拉列表中包含所有结果。
如果有人能指出我正确的方向,那就太好了。谢谢
<?php
include("conndetails.php");
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT website_name FROM user_websites WHERE username='$_SESSION[user]'"; //Selects all the websites for the user that is logged in.
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo '<h2>Download a website</h2>
<form action="downloads.php" method="get">
<select id="website_name" name="website_name">
<option name="website_name">'. $row["website_name"]. '
</option>
</select>
<input type="submit" value="Download">
</form>
<br>
<hr>
<h2>Upload to a website</h2>
<form action="upload.php" method="post" enctype="multipart/form-data">
<p>Select file to upload:</p>
<input type="file" name="zip_file" id="fileToUpload">
<p>Select a website to upload to:</p>
<select id="website_upload_name" name="website_upload_name">
<option name="website_upload_name">'. $row["website_name"]. '
</option>
</select>
<br>
<br>
<input type="submit" value="Upload" name="submit" style="position:relative; left: -1px;">
</form>
<br>
<hr>';
}}
?>
ABOUTYOU
杨__羊羊