简体   繁体   English

PHP - 在while循环中显示变量

[英]PHP - show variable in while loop

I have while loop in a PHP file and outside of that, I have one variable. 我在PHP文件中有while循环,除此之外,我有一个变量。 When I try to add this variable into while, it doesn't work. 当我尝试将此变量添加到while时,它不起作用。

example code: 示例代码:

<?

$var1 = 2999288;

while($row = mysql_fetch_array($result)){

echo $var1;

}

?>

Can anybody tell me a solution, how to echo that variable into a while? 任何人都可以告诉我一个解决方案,如何在一段时间内回应该变量? Or what I'm doing wrong? 或者我做错了什么?

Your SQL query is not returning any rows, make sure that your query is working properly before echoing results. 您的SQL查询未返回任何行,请确保在回显结果之前查询正常工作。 Also please look into prepared SQL statements, they are more safe than the traditional way that you are using. 另外,请查看准备好的SQL语句,它们比您使用的传统方法更安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM