gpt4 book ai didi

PHP:MySQL 到表

转载 作者:行者123 更新时间:2023-11-29 13:28:33 26 4
gpt4 key购买 nike

我刚刚编写了简单的 PHP 代码来打印其中一些行

这就是我的表结构的样子:

这是我的 PHP 代码:

$user = mysql_query("SELECT usr FROM ava_members");
$id = mysql_query("SELECT id FROM ava_members");
$email = mysql_query("SELECT email FROM ava_members");
$dt = mysql_query("SELECT dt FROM ava_members");

//$result = mysql_query("SELECT id,email,dt,regIP FROM ava_members ORDER BY dt LIMIT 5");
$final = "";
$final .= "<table border='1'><tr>";


/* TABELA */
$final .= "<td>Nick</td>";
$final .= "<td>ID</td>";
$final .= "<td>Email</td>";
$final .= "<td>Data</td>";
//$final .= "</tr>\n";
/* TABELA */

//user
while($row = mysql_fetch_row($user))
{
$final .= "<tr>";

foreach($row as $cell)
$final .= "<td>$cell <a href=\"\?usrdel=$cell\"\>[DELETE]</a></td>";
$final .= "</tr>\n";
}

//ID
while($row = mysql_fetch_row($id))
{
$final .= "<tr>";

foreach($row as $cell)
$final .= "<td>$cell</td>";
$final .= "</tr>\n";
}

//email

while($row = mysql_fetch_row($email))
{
$final .= "<tr>";

foreach($row as $cell)
$final .= "<td>$cell</td>";
$final .= "</tr>\n";
}

//dt
while($row = mysql_fetch_row($dt))
{
$final .= "<tr>";

foreach($row as $cell)
$final .= "<td>$cell</td>";
$final .= "</tr>\n";
}

mysql_free_result($user);
mysql_free_result($id);
mysql_free_result($email);
mysql_free_result($dt);

echo '<center>' . $final . '</center>';

有输出:

但你可以猜到这不是我想要的......我想要的输出应该如下所示:

It's pretty simple - just learn in2 html tables

最佳答案

你应该学习 SQL:

$data = mysql_query("SELECT usr, id, email, dt FROM ava_members");
while ($row = mysql_fetch_row($data))
{
$final .= "<tr>";

foreach($row AS $k => $cell) {
$final .= '<td>' . htmlspecialchars($cell);
if ($k == 'usr') {
$final .= '<td><a href="?usrdel=' . $row['id'] . '">[DELETE]</a>';
}
$final .= '</td>';
}
$final .= "</tr>\n";
}

是的,不要使用mysql_。使用 mysqli_ 代替。

关于PHP:MySQL 到表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19797322/

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