PHP EOF 仅显示循环的一个结果
我在 PHP 中使用 EOF。
问题是它只显示来自 mySQL 循环的一项。
它仅显示最后的结果。
这在EOF中有必要吗?或者我可以避免这个问题吗?
谢谢
function getYiBAdminBanner() {
global $site;
global $dir;
$queryYiBmenu = "SELECT * FROM `(YiB)_cPanel_Menu` WHERE Type = 'top'";
$resultYiBmenu=mysql_query($queryYiBmenu) or die("Errore select menu: ".mysql_error());
$countYiBmenu = mysql_num_rows($resultYiBmenu);
while($rowYiBmenu = mysql_fetch_array($resultYiBmenu)) {
$menu = "<div id=\"menu\" style=\"display:none;\"><li><a href=\"".$site['url'].$rowYiBmenu['linkHref']."\" onMouseOut=\"javascript: $('#menu').hide('9000');\"><img class=\"imgmenu\" src=\"".$site['url'].$rowYiBmenu['linkIcon']."\">".$rowYiBmenu['linkTitle']."</a></li></div>";
}
if($countYiBmenu <= 0){
$menu = "No Modules Installed";
}
$bannerCode .= <<<EOF
<div style="width:520px; background-color: #EEE; height:30px;">
{$menu}
</div>
EOF;
return $bannerCode;
}
I am using in my PHP EOF.
The problem is that it does display only one item coming from a mySQL loop.
It shows only the last result.
Is this necessary in EOF? or can I avoid this issue?
Thanks
function getYiBAdminBanner() {
global $site;
global $dir;
$queryYiBmenu = "SELECT * FROM `(YiB)_cPanel_Menu` WHERE Type = 'top'";
$resultYiBmenu=mysql_query($queryYiBmenu) or die("Errore select menu: ".mysql_error());
$countYiBmenu = mysql_num_rows($resultYiBmenu);
while($rowYiBmenu = mysql_fetch_array($resultYiBmenu)) {
$menu = "<div id=\"menu\" style=\"display:none;\"><li><a href=\"".$site['url'].$rowYiBmenu['linkHref']."\" onMouseOut=\"javascript: $('#menu').hide('9000');\"><img class=\"imgmenu\" src=\"".$site['url'].$rowYiBmenu['linkIcon']."\">".$rowYiBmenu['linkTitle']."</a></li></div>";
}
if($countYiBmenu <= 0){
$menu = "No Modules Installed";
}
$bannerCode .= <<<EOF
<div style="width:520px; background-color: #EEE; height:30px;">
{$menu}
</div>
EOF;
return $bannerCode;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:根据您的代码示例:尝试
$menu .=
或$menu = $menu 。 <您的结果>
而不是$menu = <您的结果>
。但不清楚您是否期望多个结果如果您正在循环遍历 mySQL 查询的结果,您应该执行如下操作:
http://php.net/manual/en/function.mysql-query.php
如果您正在循环访问文件的内容,您应该做一些事情像这样:
http://www.w3schools.com/php/php_file.asp
php 手册 fopen
我希望有所帮助,但你的问题不是很清楚你如何/在哪里使用 EOF。
Edit: based on your code sample: try
$menu .= <your result>
or$menu = $menu . <your result>
rather than$menu = <your result>
. But its unclear if you are expecting multiple results or notIf you are looping through the results of a mySQL query you should be doing something like this:
http://php.net/manual/en/function.mysql-query.php
If you are looping through the contents of a file you should be doing something like this:
http://www.w3schools.com/php/php_file.asp
php manual fopen
I hope that helps but your question isn't very clear on how/where your using EOF.