且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP MySQL 通过数据库中的 id 显示数据 - ***放置

更新时间:2023-01-31 09:37:38

<?php
$db = mysql_connect("xxx","xxx","xxx") or die("Database Error");
mysql_select_db("caisafety",$db);

$id = $_GET['id'];
$id = mysql_real_escape_string($id);
$query = "SELECT * FROM `cert_rr` WHERE `id`='" . $id . "'";
$result = mysql_query($query);

//you need to retrieve every row and save to an array for later access
        for($rows = array(); $tmp = mysql_fetch_array($result);)
        {
            $rows[] = $tmp;
        }

//now you can use the $rows array where every you want e.g. with the code from Zhube
?>

....

<table><?php foreach($rows as $r):
    <td><?php echo $r['id'] ?></td><?php endforeach ?>
</table>

来自

while($row = mysql_fetch_array( $result )) {

echo "<br><br>";
echo $row['basic3'];
echo $row['basic2'];
echo $row['basic1'];
}

你只保存最后一行