我正在尝试创建一个php脚本,它将从表中的数据库中获取客户端数据。该脚本工作正常,正确获取数据库字段。现在我想在每个客户信息旁边添加一个链接。该链接应该是www.domain.com/check?clientid=$id&number=$phonenumber
我该怎么做? 它的表格和客户详细信息按顺序排列。请帮帮我?
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname, phonenumber, city, country, email FROM clients ORDER BY ID ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Name</th><th>Phone Number</th><th>Country</th><th>Email</th><th>Send SMS</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]. "</td><td>" . $row["phonenumber"]. "</td><td>" . $row["city"]. " "
. $row["country"]. "</td><td>" . $row["email"]. "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
答案 0 :(得分:0)
我同意Marcosh(在评论中),所以这会给你这个代码(在if(...){和}之间):
echo "<table><tr><th>ID</th><th>Name</th><th>Phone Number</th><th>Country</th><th>Email</th><th>Send SMS</th><th>Link to page</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]."</td><td>" . $row["phonenumber"]. "</td><td>" . $row["city"]. " ". $row["country"]. "</td><td>" . $row["email"]. "</td><td><a href='www.domain.com/check?clientid=" . $row["id"] . "&number=" . $row['phonenumber'] . ">Click me!</a></td></tr>";
}
echo "</table>";
注1:这将添加一个包含文字的链接&#34;点击我!&#34;。我想你可能想改变它。您可能还想更改标题(当前&#34;链接到页面&#34;)
注意2:如果您使用的是PHP 5.5或更高版本,您也可以使用
echo "blablabla<td>{$row['id']}</td>etc..."
而不是
echo "blablabla<td>" . $row['id'] . "</td>etc..."
答案 1 :(得分:0)
感谢@ivo的帮助,我已经学会了如何完成这件事:
<td><form action='https://control.domain.com/api/sendhttp.php' method='GET'><input type='hidden' name='authkey' value='74685AiSz3dkBX5467773f'><input type='hidden' name='mobiles' value='" . $row['phonenumber'] . "'><input type='hidden' name='sender' value='hostbi'><input type='hidden' name='route' value='4'><textarea name='message' cols='55'>Leave a message</textarea><input type='submit' value='Click me!'></form></td>