gpt4 book ai didi

php - 在 div 标签中从 MySQL 接收数据

转载 作者:行者123 更新时间:2023-11-29 21:45:32 26 4
gpt4 key购买 nike

我的代码现在一团糟,但我只是尝试一些东西。但我有以下页面:

索引:

<html>

<head>
<link rel="stylesheet" type="text/css" href="css\placing.css">
<title>Numbers</title>
</head>

<body>
<div class="topbar">
sf
</div>
<div class="talraekke">
<p>test</p>
</div>
<div class="content">
<p>Enter The Number</p>
<form action="action.php" method="post" >
<input type="value" name="numbervalue">
<input type="submit">
</form>
</div>

</body>
</html>

<?php
include 'action.php';
?>

还有我的actionpage.php:

<?php

$username = "root";
$password = "root";
$hostname = "127.0.0.1:3306";

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//echo "<br><br>Connected to MySQL<br><br>";

//select a database to work with
$selected = mysql_select_db("roulette_db",$dbhandle)
or die("Could not select any database");


echo "<h1>Hello " . $_POST["numbervalue"] . "</h1>";

// Insert To Database
$strSQL = "INSERT INTO numbertable(numbers) VALUES('" . $_POST["numbervalue"] . "')";
// The SQL statement is executed
mysql_query($strSQL) or die (mysql_error());

// SQL query
$strSQL = "SELECT * FROM numbertable";

// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);

// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {

// Write the value of the column FirstName (which is now in the array $row)
echo $row['numbers'] . "<br />";
}

// The SQL statement is executed
mysql_query($strSQL) or die (mysql_error());

// Close the database connection
mysql_close();
?>

从数据库中,我收到了一些已放入表单中的数字。但我希望这些数字位于:

<div class="talraekke">
<p>test</p>
</div>

但是我怎样才能在我的 div 标签中调用这些数据呢?

致以诚挚的问候麦兹

最佳答案

只需替换代码中的以下部分即可。

echo "<div class='talraekke'>";
while($row = mysql_fetch_array($rs)) {
echo "<p>".$row['numbers'] . "</p><br />";
}
echo "</div>";

关于php - 在 div 标签中从 MySQL 接收数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34141285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com