且构网

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

将来自mysql行的数据显示为php中的列

更新时间:2021-12-29 00:58:56

我正在做假设,请记住在尝试新代码之前始终备份数据库.从经验上讲.

I am making assumptions, and please remember to always take a backup of your database before trying new code. Speaking from experience.

如果您使用的是PHP和MySQLi,请尝试以下操作,如果您想显示所有表,则将这些代码记下来,我假设您将转到另一个页面以显示单个表论坛人.

If you are using PHP and MySQLi, try the following, if you would like to show a table with all of them, you have that code down, I am assuming you are going to a different page to show the single table fora person.

这就是我要做的,当您单击一个名称时,将其转到person.php?person=Fred

Here is what I would do, when you click on a name, have it go to a page like person.php?person=Fred

这是我要用于该页面的代码:

here is the code I would use for that page:

//Your DB connection details go here.
$sql = "SELECT * FROM table WHERE name = '$_GET[person]'";
$sql_con = mysqli_query($con, $sql);
$data = mysqli_fetch_array($sql_con);
echo '<h2>Data for '.$data['name'].'</h2><br />';
echo '<table><tr><th>Items</th><th>Count</th></tr><tr>'; // SET UP YOUR TABLE
echo '<td>Item 1</td><td>'.$data['item1'].'</td></tr><tr>';
echo '<td>Item 2</td><td>'.$data['item2'].'</td></tr>'; // CONTINUE FOR EVERY ITEM YOU HAVE
echo '</table>';

应该这样做,如果那不是您想要的,请告诉我.

That should do it, if that is not what you were looking for, let me know.