donglei2022 2011-06-01 21:10
浏览 66
已采纳

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

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;
}
  • 写回答

1条回答 默认 最新

  • dqcwl02022 2011-06-01 21:19
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题