PHP EOF shows only one result from loop

前端 未结 1 1152
广开言路
广开言路 2021-01-29 02:22

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

相关标签:
1条回答
  • 2021-01-29 02:31

    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.

    0 讨论(0)
提交回复
热议问题