Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php创建左侧带有表头的表?_Php_Mysql - Fatal编程技术网

如何使用php创建左侧带有表头的表?

如何使用php创建左侧带有表头的表?,php,mysql,Php,Mysql,我想创建如下表: 问题是,我想从数据库生成它 $sql = "SELECT name, email, tel, address FROM info where id=1"; $res = mysql_query($sql); $row = mysql_fetch_assoc($res); $output="<table> <tr> <th>Name</th> <th>E-mail</th> <th>Phone

我想创建如下表:

问题是,我想从数据库生成它

$sql = "SELECT name, email, tel, address FROM info where id=1";
$res = mysql_query($sql);
$row = mysql_fetch_assoc($res);
$output="<table>
<tr>
<th>Name</th>
<th>E-mail</th>
<th>Phone number</th>
<th>Address</th>
</tr>\n";

$output.="<tr>
    <td>{$row['name']}</td>
    <td>{$row['email']}</td>
    <td>{$row['tel']}</td>
    <td>{$row['address']}</td>
</tr>";

$output.="</table>\n";
$sql=“从id=1的信息中选择姓名、电子邮件、电话、地址”;
$res=mysql\u查询($sql);
$row=mysql\u fetch\u assoc($res);
$output=”
名称
电子邮件
电话号码
地址
\n”;
$output.=”
{$row['name']}
{$row['email']}
{$row['tel']}
{$row['address']}
";
$output.=“\n”;

我想要一个有效的代码,但我不知道该怎么做。

您希望将
放在自己的
中,它更像

$output = "<table>\n";
$output.="<tr>
<th>Name</th><td>{$row['name']}</td>
<th>E-mail</th><td>{$row['email']}</td>
<th>Phone number</th><td>{$row['tel']}</td>
<th>Address</th><td>{$row['address']}</td>
</tr>";
$output=“\n”;
$output.=”
名称{$row['Name']}
电子邮件{$row['email']}
电话号码{$row['tel']}
地址{$row['Address']}
";

如果有多行怎么办?代码不起作用。输出是:一行中的th td th td。等等,代码中根本没有循环,所以这只会做一个不,我没有,我只是问了一下。我用你的答案解决了我的问题,但我在每个地方都加了一个额外的tr。现在可以了。tr th/th td/td/tr