这是我的完整页面代码:
<?php
$servername = "localhost";
$username = "root";
$password = "null";
$dbname = "logs";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result = mysql_query("SELECT * FROM 'd82Kap3'");
$row = mysql_fetch_array($result);
echo $row['ip'];
?>
这是我的表结构:http://prntscr.com/7we7ck
我试图让它回显字段中的所有记录&#34; ip&#34;。
答案 0 :(得分:2)
使用while
循环。
示例强>
$result = mysql_query("SELECT * FROM 'd82Kap3'");
while($row = mysql_fetch_array($result))
{
echo $row['ip']."<br />";
}
注意强>
自PHP 5.5.0起, mysql
扩展名已弃用,将来将被删除。相反,应该使用MySQLi或PDO_MySQL扩展。
<强>更新强>
<?php
$servername = "localhost";
$username = "root";
$password = "null";
$dbname = "logs";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result = $conn->query("SELECT * FROM `d82Kap3`");
while($row = $result->fetch_array())
{
echo $row['ip']."<br />";
}
?>
答案 1 :(得分:0)
不要混用mysql
和mysqli
<?php
$servername = "localhost";
$username = "root";
$password = "null";
$dbname = "logs";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result = $conn->query("SELECT * FROM d82Kap3");
while($row = $result->fetch_assoc())
echo $row['ip'];
?>
答案 2 :(得分:0)
使用以下代码:
$result = mysql_query("SELECT * FROM 'd82Kap3'");
while($row = mysql_fetch_array($result))
{
echo $row['ip'];
}