繁体   English   中英

在 html 中回显 php

[英]echo php inside html

$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>

有人可以建议我如何制作干净的代码吗?

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

<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. <table class='fixed'/>应该定义 while 循环的顶部。
  5. 我们从不在表中使用<br />
  6. 所有<td>都应该在<tr>和 .
  7. 我们从不指向这样的数据$res[0]

输入这个代码

<?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>
<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM