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.

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

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM