PHP EOF仅显示循环的一个结果 [英] PHP EOF shows only one result from loop
问题描述
我在PHP EOF中使用。
I am using in my PHP EOF.
问题是它确实只显示了来自mySQL循环的一项。
The problem is that it does display only one item coming from a mySQL loop.
它仅显示最后一个结果。
It shows only the last result.
在EOF中这是否必要?还是可以避免这个问题?
Is this necessary in EOF? or can I avoid this issue?
谢谢
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;
}
推荐答案
编辑:根据您的代码示例:尝试 $ menu。=<您的结果>
或 $ menu = $ menu。 < your result>
而不是 $ menu =< your result>
。但是不清楚是否期望多个结果
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 not
如果要遍历mySQL查询的结果,则应该执行以下操作:
If you are looping through the results of a mySQL query you should be doing something like this:
$query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'",
mysql_real_escape_string($firstname),
mysql_real_escape_string($lastname));
// Perform Query
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo $row['firstname'];
echo $row['lastname'];
echo $row['address'];
echo $row['age'];
}
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:
<?php
$file = fopen("welcome.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
http://www.w3schools.com/php/php_file.asp
我希望这对您有所帮助不清楚如何/在何处使用EOF。
I hope that helps but your question isn't very clear on how/where your using EOF.
这篇关于PHP EOF仅显示循环的一个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!