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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器