【问题标题】:echo php inside html在 html 中回显 php
【发布时间】:2015-09-15 10:58:33
【问题描述】:
$rst=mysqli_query($link, "SELECT * FROM flux_receptie WHERE status_procesare ='PRELUAT' AND status_solutionare ='' ORDER BY ora_preluare DESC LIMIT 5");
while($res = mysqli_fetch_array($rst)) 
        if(($res)==TRUE)
         echo "
<table class='fixed'>
<td>$res[0]</td><br /><br />
<td>$res[2]</td><br />
<td>&#10148; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$res[12]</td>
";

?>

有没有办法重新创建干净的代码?我试图重新创建它,但它没有回显来自sql 的值:

$rst=mysqli_query($link, "SELECT * FROM flux_receptie WHERE status_procesare ='PRELUAT' AND status_solutionare ='' ORDER BY ora_preluare DESC LIMIT 5");
while($res = mysqli_fetch_array($rst)) 
        if(($res)==TRUE)
        ?>

<table class='fixed'>
<td><? print $res[0]; ?></td><br /><br />
<td><? print $res[2]; ?></td><br />
<td>&#10148; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<? print $res[12]; ?></td>

有人可以告诉我如何编写干净的代码吗?

【问题讨论】:

  • 使用大量   不是一个好习惯。        .避开他们
  • 谢谢。我会记住这一点的。

标签: php mysql printf echo


【解决方案1】:

您的编码中有很多错误。首先改进它,然后构建应用程序。

<table class='fixed'>
    <?php
        $rst = mysqli_query($link, "SELECT *
                                    FROM flux_receptie 
                                    WHERE status_procesare = 'PRELUAT' 
                                      AND status_solutionare = '' 
                                    ORDER BY ora_preluare DESC 
                                    LIMIT 5");
        while($res = mysqli_fetch_array($rst, MYSQLI_ASSOC)) {
    ?>

    <tr>
        <td><?php echo $res['database_field_one']; ?></td>
        <td><?php echo $res['database_field_two']; ?></td>
        <td>&#10148; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<?php echo $res['database_field_three']; ?></td>
    </tr>

    <?php
        }
    ?>
</table>

列出其中一些

  1. mysqli_fetch_array 中缺少参数
  2. 不用if(($res)==TRUE),了解一下empty()
  3. while 之后循环没有花括号{}
  4. &lt;table class='fixed'/&gt; 应该定义 while 循环的顶部。
  5. 我们从不在表内使用&lt;br /&gt;
  6. 所有的&lt;td&gt;都应该定义在&lt;tr&gt;和.
  7. 我们从不指向这样的数据$res[0]

【讨论】:

  • 哇。我在开始。没想到出现这么多错误...非常感谢!
【解决方案2】:

输入这段代码

<?php
 $rst=mysqli_query(
              $link, 
              "SELECT * FROM flux_receptie WHERE status_procesare ='PRELUAT' AND status_solutionare ='' ORDER BY ora_preluare DESC LIMIT 5"
 );
while($res = mysqli_fetch_array($rst)) {
?>

<table class='fixed'>
    <td><?php echo $res[0];?></td><br /><br />
    <td><?php echo $res[2];?></td><br />
    <td>&#10148; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<?php echo $res[12];?> </td>
</table>

【讨论】:

    【解决方案3】:
    <table class='fixed'>
        <?php
            $rst = mysqli_query($link, "SELECT *
                                        FROM flux_receptie 
                                        WHERE status_procesare = 'PRELUAT' 
                                          AND status_solutionare = '' 
                                        ORDER BY ora_preluare DESC 
                                        LIMIT 5");
            while($res = mysqli_fetch_array($rst, MYSQLI_ASSOC)) {
        ?>
    
        <tr>
            <td><?php echo $res['fieldname']; ?></td>
            <td><?php echo $res['fieldname2']; ?></td>
            <td>&#10148; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<?php echo $res['fieldanme3']; ?></td>
        </tr>
    
        <?php
            }
        ?>
    </table>
    

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 2021-04-12
      • 1970-01-01
      • 2017-09-11
      • 2018-08-25
      • 2021-09-06
      • 1970-01-01
      相关资源
      最近更新 更多