作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够创建多个用户,并将他们的信息回显到welcome.php,但是当我创建第一个用户时,第一个用户信息出现在welcome.php中,当我创建第二个用户时,第二个用户信息的携带第一个用户信息忽略我创建的第二个用户信息,我不知道是否有人能理解我,所以我想知道如何分离每个用户信息并允许它在第一个用户输入其用户名和密码时回显它回显第一个用户的信息,当第二个用户输入其用户名和密码时,它仅回显第二个用户的信息,而不将其加入到第一个用户的信息中,只是以一种方式将它们分开,当第一个用户输入其用户名和密码时,它会回显第一个用户的信息,当第二个用户输入其用户名和密码时,它会回显第二个用户的信息,我希望你们能理解我的意思,对我的英语表示歉意,只是希望是可能的。
这是我迄今为止尝试过的:
<?php
// Connect to the database
$db = mysql_connect("$Sname","$Uname","$Pname") or die("Could not connect to the Database.");
$select = mysql_select_db("$Dname") or die("Could not select the Database.");
$tnumber2 = "{$_SESSION['tnumber2']}";
$sql="SELECT * FROM `$Tname` LIMIT 0, 25 ;";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
并且我还在同一个欢迎中回显了另一张 table 的信息,即:
<?php
// Connect to the database
$db = mysql_connect("$Sname","$Uname","$Pname") or die("Could not connect to the Database.");
$select = mysql_select_db("$Dname") or die("Could not select the Database.");
$tnumber2 = "{$_SESSION['tnumber2']}";
$sql="SELECT * FROM `$UPname` LIMIT 0, 25 ;";
$result=mysql_query($sql);
?>
在这一点上,我用 html 表格来呼应这一点
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td style="height:27px; color:#333" bgcolor="#E6E6E6"><strong><?php echo $rows['pdate']; ?></strong></td>
<td class="style007" style="height: 27px; width: 111px;" color:"#333" bgcolor="#E6E6E6" ><strong><?php echo $rows['act']; ?></strong></td>
<td class="style007" style="height: 27px" color:"#333" bgcolor="#E6E6E6"><strong><?php echo $rows['paddress']; ?></strong></td>
<td class="style007" style="height: 27px; width: 60px;" color:"#333" bgcolor="#E6E6E6"><strong><?php echo $rows['up']; ?></strong></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
任何有关如何使其完美的帮助将不胜感激
最佳答案
让我们尝试重写此代码并使用 MySQLi 来代替?
<?php
// Making the connection.
$connection = new mysqli('localhost', "root", "ascent", "tcms");
// Making sure that the connection is successful.
if ($connection->connect_error)
{
trigger_error("Database connection error: " . $connection->connect_error, E_USER_ERROR);
}
// Getting the result from the table.
$result = $connection->query("SELECT * FROM phptracker_peers LIMIT 0, 25;");
// Checking if there is a result or the query is wrong.
$result === FALSE ? trigger_error("Database query error: " . $result->error, E_USER_ERROR) : NULL;
// Echo the details of the users.
while ($row = $result->fetch_assoc()) // Fetching it with the column names, instead of number
{
?>
<tr>
<td style="height:27px; color:#333" bgcolor="#E6E6E6"><strong><?php echo $row['pdate']; ?></strong></td>
<td class="style007" style="height: 27px; width: 111px;" color:"#333" bgcolor="#E6E6E6" ><strong><?php echo $row['act']; ?></strong></td>
<td class="style007" style="height: 27px" color:"#333" bgcolor="#E6E6E6"><strong><?php echo $row['paddress']; ?></strong></td>
<td class="style007" style="height: 27px; width: 60px;" color:"#333" bgcolor="#E6E6E6"><strong><?php echo $row['up']; ?></strong></td>
</tr>
<?php
}
?>
另一个查询与 MySQLi 的查询方式相同,只有一处不同:您不必再次连接,只需使用此 $connection
即可。
为什么使用 MySQLi? MySQL 在 PHP 5.5 中已弃用,并将在下一版本中删除。它缺少 PDO/MySQLi 所具有的许多功能和安全性。
关于php - 如何将同一个表中的多个用户信息回显并分离到他们的每个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23195026/
我是一名优秀的程序员,十分优秀!