Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php&;带循环的MySQL显示表_Php_Mysql - Fatal编程技术网

php&;带循环的MySQL显示表

php&;带循环的MySQL显示表,php,mysql,Php,Mysql,我需要显示表中的结果,但是我的循环不会相应地生成表,每个结果都循环TH,请协助 <?php foreach ($results as $results) : ?> <table border="1"> <tr> <th>Date</th> <th>GBR</th> <th>EUR</th> <th>USD

我需要显示表中的结果,但是我的循环不会相应地生成表,每个结果都循环TH,请协助

<?php foreach ($results as $results) :  ?>
<table border="1">
    <tr>
        <th>Date</th>
        <th>GBR</th>
        <th>EUR</th>
        <th>USD</th>
    </tr>
    <tr>
        <td><?php echo $results['date'];?></td>
        <td><?php echo $results['gbr']; ?></td>
        <td><?php echo $results['eur']; ?></td>
        <td><?php echo $results['usd']; ?></td>
    </tr>
</table>
<?php endforeach; ?>

日期
GBR
欧元
美元

您需要在循环中编写tr

试试这个:

<table border="1">
  <tr>
    <th>Date</th>
    <th>GBR</th>
    <th>EUR</th>
    <th>USD</th>
  </tr>

  <?php foreach ($results as $results) :  ?>

  <tr>
        <td><?php echo $results['date'];?></td>
        <td><?php echo $results['gbr']; ?></td>
        <td><?php echo $results['eur']; ?></td>
        <td><?php echo $results['usd']; ?></td>
  </tr>

  <?php endforeach; ?>

</table>

日期
GBR
欧元
美元

只需在需要动态显示数据的地方使用
foreach
循环即可

<table border="1">
    <tr>
        <th>Date</th>
        <th>GBR</th>
        <th>EUR</th>
        <th>USD</th>
    </tr>
<?php foreach ($results as $results) :  ?>  
    <tr>
        <td><?php echo $results['date'];?></td>
        <td><?php echo $results['gbr']; ?></td>
        <td><?php echo $results['eur']; ?></td>
        <td><?php echo $results['usd']; ?></td>
    </tr>
<?php endforeach; ?>
</table>    

日期
GBR
欧元
美元

不要每次都循环表。只要开始循环到


对于每个循环,无需包含表和th标记,只需将tr放入循环即可

 <table border="1">
     <tr>
      <th>Date</th>
      <th>GBR</th>
      <th>EUR</th>
     <th>USD</th>
   </tr>
    <?php foreach ($results as $result) :  ?>
     <tr>
        <td><?=  $result['date'];?></td>
        <td><?=  $result['gbr']; ?></td>
        <td><?=  $result['eur']; ?></td>
        <td><?=  $result['usd']; ?></td>
    </tr>

    <?php endforeach; ?>

    </table>

日期
GBR
欧元
美元

试试这段代码,希望对您有所帮助

谢谢,它现在可以工作了,我完全按照上面的说明键入了。
 <table border="1">
     <tr>
      <th>Date</th>
      <th>GBR</th>
      <th>EUR</th>
     <th>USD</th>
   </tr>
    <?php foreach ($results as $result) :  ?>
     <tr>
        <td><?=  $result['date'];?></td>
        <td><?=  $result['gbr']; ?></td>
        <td><?=  $result['eur']; ?></td>
        <td><?=  $result['usd']; ?></td>
    </tr>

    <?php endforeach; ?>

    </table>