Php Mysqli不希望在while循环中打印来自database的数据
我知道这个问题问了这么多时间,但我的代码中有一些问题,我不想在while循环中打印,当我在while循环中给出id时,它只显示一行,更多信息请参见代码Php Mysqli不希望在while循环中打印来自database的数据,php,mysqli,Php,Mysqli,我知道这个问题问了这么多时间,但我的代码中有一些问题,我不想在while循环中打印,当我在while循环中给出id时,它只显示一行,更多信息请参见代码 <?php include("../../config/db_config.php"); $email_query = $con_db->query("SELECT * FROM emailtemplate") or die("Erro"); if($email_query->num_rows >
<?php
include("../../config/db_config.php");
$email_query = $con_db->query("SELECT * FROM emailtemplate") or die("Erro");
if($email_query->num_rows > 0){
while($row = $email_query->fetch_assoc()) {
$templatename = $row["templatename"]. "<br>";
}
}
echo $templatename;
?>
您可以在while循环之外声明变量。
然后使用.=运算符将其附加到while循环中
<?php
include("../../config/db_config.php");
$email_query = $con_db->query("SELECT * FROM emailtemplate") or die("Erro");
$templatename = "";
if($email_query->num_rows > 0){
while($row = $email_query->fetch_assoc()) {
$templatename .= $row["templatename"]. "<br>";
}
}
echo $templatename;
?>
您可以使用这个。这可以帮助你
<?php
include("../../config/db_config.php");
$templatename = "";
$email_query = $con_db->query("SELECT * FROM emailtemplate") or die("Erro");
if($email_query->num_rows > 0){
while($row = $email_query->fetch_assoc()) {
$templatename .= $row["templatename"]. "<br>";
echo $row["templatename"];
}
}
echo $templatename;
?>
您只看到一行,因为您在while循环外部打印变量,所以需要在内部打印变量。