PHP EOF 仅显示循环的一个结果

发布于 2024-11-10 16:31:34 字数 997 浏览 5 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生寂 2024-11-17 16:31:34

编辑:根据您的代码示例:尝试 $menu .=$menu = $menu 。 <您的结果> 而不是 $menu = <您的结果>。但不清楚您是否期望多个结果

如果您正在循环遍历 mySQL 查询的结果,您应该执行如下操作:

$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

如果您正在循环访问文件的内容,您应该做一些事情像这样:

<?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

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 not

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

php manual fopen

I hope that helps but your question isn't very clear on how/where your using EOF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文