dongmu1989 2013-09-08 14:49 采纳率: 0%
浏览 21
已采纳

php printf不适用于<li type =“1”>

I have php prinf and doesn't work with <li type="1">. It works only with chrome browser, what can i do to make it work with all browsers?

My php code is very long and ill provide shorter version:

sample code is like this:

<ul>
<table>
$result = mysql_query("........",$db);

if(mysql_num_rows($result) > 0)
{
    $myrow = mysql_fetch_array($result);
do
{
    printf ("

<tr><td><li type="1">%s</li></td></tr>",$myrow["var"]);
}
while ($myrow = mysql_fetch_array($result));    
}
else
{
    echo "<p align='center'>error...</p>";
}

</table></ul>

here is screenshot

  • 写回答

1条回答 默认 最新

  • dtrn74832 2013-09-08 15:08
    关注

    from the sample code provided you have messed up the tag order. try this. Note i have moved the tag orders. Hope this is what you want to achieve. too unclear from the question.

    <table>
    <?php
    $result = mysql_query("........",$db);
    
    if(mysql_num_rows($result) > 0)
    {
        echo '<tr><td><ul>';
        $myrow = mysql_fetch_array($result);
        do
        {
            printf ("<li type=\"1\">%s</li>",$myrow["var"]);
        }
        while ($myrow = mysql_fetch_array($result)); 
        echo '</ul></td></tr>';
    }
    else
    {
        echo "<p align='center'>error...</p>";
    }
    ?>
    </table>
    

    tag order should be. you cannot insert <table> as a child of <ul>. <ul> can have only <li> as child.

    <table>
       <tr>
           <td>
               <ul>
                   <li>...</li>
               </ul>
           </td>
       </tr>
    </table>
    

    Edit:
    You may not need the <ul>...</ul> tags. you can do it with simple table. Try this

    <?php
    $result = mysql_query("........",$db);
    
    if(mysql_num_rows($result) > 0)
    {
        echo '<table>';
        $rownum=1; //just a counter here, if have other real value then use it
        $myrow = mysql_fetch_array($result);
        do
        {
            printf ("<tr><td>%d</td><td>%s</td></tr>", $rownum, $myrow["var"]);
            $rownum++;
        }
        while ($myrow = mysql_fetch_array($result)); 
        echo '</table>';
    }
    else
    {
        echo "<p align='center'>error...</p>";
    }
    ?>
    

    and if you want to do it with just ordered list you can do it like the following

    <?php
    $result = mysql_query("........",$db);
    
    if(mysql_num_rows($result) > 0)
    {
        echo '<ol>';
        $myrow = mysql_fetch_array($result);
        do
        {
            printf ("<li>%s</li>", $myrow["var"]);
            $rownum++;
        }
        while ($myrow = mysql_fetch_array($result)); 
        echo '</ol>';
    }
    else
    {
        echo "<p align='center'>error...</p>";
    }
    

    Note: the type attribute of <li> is deprecated in HTML 4.01. and is not supported in HTML 5.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度