我是一名php初学者,我一直试图将selectbox添加两天但没有成功。这是代码。我需要让它成为selectbox而不是可点击的链接。
这是我正在进行的工作
echo "<b><a href=\"readphp.php?id={$row['id']}\">{$row['name']}</a></b>";
提前谢谢。
<!DOCTYPE html>
<html>
<head>
<title>Read</title>
<meta content="noindex, nofollow" name="robots">
<link href="style.css" rel="stylesheet" type="text/css">
<meta charset="utf-8">
</head>
<body>
<div class="maindiv">
<div class="divA">
<div class="title">
<h2>Read Data Using PHP</h2>
</div>
<div class="divB">
<div class="divD">
<p>Click On Menu</p>
<?php
$connection = mysql_connect("localhost", "user", "pass"); // Establishing Connection with Server
$db = mysql_select_db("dbname", $connection); // Selecting Database
//MySQL Query to read data
$query = mysql_query("select * from orders", $connection);
while ($row = mysql_fetch_array($query)) {
**echo "<b><a href=\"readphp.php?id={$row['id']}\">{$row['name']}</a></b>";**
echo "<br />";
}
?>
</div>
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query1 = mysql_query("select * from orders where id=$id", $connection);
while ($row1 = mysql_fetch_array($query1)) {
?>
<div class="form">
<h2>---Details---</h2>
<!-- Displaying Data Read From Database -->
<span>Name:</span> <?php echo $row1['name']; ?><br />
<span>E-mail:</span> <?php echo $row1['email']; ?><br />
<span>Contact No:</span> <?php echo $row1['phone']; ?><br />
<span>Address:</span> <?php echo $row1['address']; ?>
</div>
<?php
}
}
?>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>
<?php
mysql_close($connection); // Closing Connection with Server
?>
</body>
</html>
答案 0 :(得分:0)
<p>Click On Menu</p>
<?php
$connection = mysql_connect("localhost", "user", "pass"); // Establishing Connection with Server
$db = mysql_select_db("dbname", $connection); // Selecting Database
//MySQL Query to read data
$query = mysql_query("select * from orders", $connection);
while ($row = mysql_fetch_array($query)) {
echo "<b><a href=\"readphp.php?id={$row['id']}\">{$row['name']}</a></b>";
echo "<br />";
}
?>
</div>
改为:
<p>Click On Menu</p>
<select name="post_request_value">
<?php
$connection = mysql_connect("localhost", "user", "pass"); // Establishing Connection with Server
$db = mysql_select_db("dbname", $connection); // Selecting Database
//MySQL Query to read data
$query = mysql_query("select * from orders", $connection);
while ($row = mysql_fetch_array($query)) {
echo "<option value=\"$row['name']\">".$row['display_name']."</option>";
echo "<br />";
}
?>
</select>
</div>
然后如果您希望选项 act 就像链接一样,您可以使用javascript来监听onchange事件,并根据选择重定向到链接。