php自动返回到表中
我知道有类似的问题,但我找不到具体的答案。 我是新来PHP的,所以很抱歉 目前已列出此信息,但我希望将其放在表格中:php自动返回到表中,php,html,echo,Php,Html,Echo,我知道有类似的问题,但我找不到具体的答案。 我是新来PHP的,所以很抱歉 目前已列出此信息,但我希望将其放在表格中: <?php include ('connect.php'); $sql ="SELECT * FROM tbl_venues"; $res = mysql_query ($sql) or die( mysql_error() ); if ( mysql_num_rows($res) > 0 ) { while ( $row = mysql_fetch_a
<?php
include ('connect.php');
$sql ="SELECT * FROM tbl_venues";
$res = mysql_query ($sql) or die( mysql_error() );
if ( mysql_num_rows($res) > 0 ) {
while ( $row = mysql_fetch_assoc($res) ) {
echo 'Venue Name:' . $row["venue_name"] ."<br />";
echo 'Venue Description:' . $row["venue_description"] ."<br />";
echo 'Venue Address:' . $row["venue_adress"] ."<br />";
echo 'Venue Type:' . $row["venue_type"] ."<br />";
echo '<a href="venueedit.php?venueid='.$row["venue_id"].'">Edit</a>';
echo '<hr>';
}
}
?>
我还没有从类似的案例中得到任何建议,我试图手动地将每个元素都输出。有可能实现自动化吗?从句法上说,我不擅长这个。非常感谢您的帮助。若要将HTML标记添加到表格中,请执行以下操作:
<?php
include ('connect.php');
$sql ="SELECT * FROM tbl_venues";
$res = mysql_query ($sql) or die( mysql_error() );
if ( mysql_num_rows($res) > 0 ) {
echo '<table>';
while ( $row = mysql_fetch_assoc($res) ) {
echo '<tr>';
echo '<td> Venue Name:' . $row["venue_name"] ."</td>";
echo '<td>Venue Description:' . $row["venue_description"] ."</td>";
echo '<td>Venue Address:' . $row["venue_adress"] ."</td>";
echo '<td>Venue Type:' . $row["venue_type"] ."</td>";
echo '<td><a href="venueedit.php?venueid='.$row["venue_id"].'">Edit</a</td>';
echo '</tr>';
}
echo '</table>'
}
?>
尝试使用EOF。在大多数情况下,这是一个非常大的节省时间的方法,并且在将php代码片段插入html文件时非常有用
<?php
include ('connect.php');
$sql ="SELECT * FROM tbl_venues";
$res = mysql_query ($sql) or die( mysql_error() );
if ( mysql_num_rows($res) > 0 ) {
echo "<table>";
while ( $row = mysql_fetch_assoc($res) ) {
echo <<<EOF
<tr>
<td>Venue Name: {$row['venue_name']}</td>
<td>Venue Description: {$row['venue_description']}<td>
<td>Venue Address: {$row['venue_adress']}</td>
<td>Venue Type: {$row['venue_type']}</td>
<td><a href="venueedit.php?venueid={$row['venue_id']}">Edit</a></td>
</tr>
EOF;
}
echo "</table>";
}
?>
您可以在PHP中使用HTML,也可以使用echo
此外,我建议您使用PDO或MySQLi,因为MySQL现在已不推荐使用,这意味着它是不安全的 此代码应将数据输出到格式正确的表中:
<?php
include ('connect.php');
$sql ="SELECT * FROM tbl_venues";
$res = mysql_query ($sql) or die( mysql_error() );
?>
<table>
<tr>
<th>Venue Name</th>
<th>Description</th>
<th>Address</th>
<th>Type</th>
<th>Edit</th>
</tr>
<?php
if ( mysql_num_rows($res) > 0 ) {
while ( $row = mysql_fetch_assoc($res) ) {
?>
<tr>
<td><?php echo $row["venue_name"]; ?></td>
<td><?php echo $row["venue_description"]; ?></td>
<td><?php echo $row["venue_address"]; ?></td>
<td><?php echo $row["venue_type"]; ?></td>
<td><?php echo '<a href="venueedit.php?venueid='.$row["venue_id"].'">Edit</a>'; ?></td>
</tr>
<?php
}
}
?>
</table>
我建议你加一张这样的表格 它更容易、更干净。。再加上组织良好
<?php
include ('connect.php');
$sql ="SELECT * FROM tbl_venues";
$res = mysql_query ($sql) or die( mysql_error() );
$result_table = "";
if ( mysql_num_rows($res) > 0 ) {
while ( $row = mysql_fetch_assoc($res) ) {
//collect rows from database
$name = $row["venue_name"] ;
$v_desc = $row["venue_description"] ;
$v_add =$row["venue_adress"] ;
$v_type=$row["venue_type"] ;
//append table with results and echo the variables
$result_table .="<table><tr><td>$name</td>. <td>$v_desc</td> <td>$v_add</td> <td>$v_type</td><td>'<a href="venueedit.php?venueid='.$row["venue_id"].'">Edit</a>'</td><tr></table>";
}
} Else { $result_table .= "No data found";}
?>
<html>
<body>
<div>
<?php echo $result_table; ?>
</div>
</body>
</html>
请说得更具体一点,因为您想回显一个包含mysql表数据的表?上面的数据,如场馆名称、场馆描述、场馆地址和场馆类型。如代码中所示,它作为一个列表,后跟一个编辑链接进行回音。我希望在表格中提供确切的信息format@user3523964所以,把桌子放在桌子上,而不是坐着,这叫做heredoc,而不是EOF。
<?php
include ('connect.php');
$sql ="SELECT * FROM tbl_venues";
$res = mysql_query ($sql) or die( mysql_error() );
$result_table = "";
if ( mysql_num_rows($res) > 0 ) {
while ( $row = mysql_fetch_assoc($res) ) {
//collect rows from database
$name = $row["venue_name"] ;
$v_desc = $row["venue_description"] ;
$v_add =$row["venue_adress"] ;
$v_type=$row["venue_type"] ;
//append table with results and echo the variables
$result_table .="<table><tr><td>$name</td>. <td>$v_desc</td> <td>$v_add</td> <td>$v_type</td><td>'<a href="venueedit.php?venueid='.$row["venue_id"].'">Edit</a>'</td><tr></table>";
}
} Else { $result_table .= "No data found";}
?>
<html>
<body>
<div>
<?php echo $result_table; ?>
</div>
</body>
</html>