Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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 while循环不带表显示mysql结果_Php_Mysql_List_Loops - Fatal编程技术网

使用php while循环不带表显示mysql结果

使用php while循环不带表显示mysql结果,php,mysql,list,loops,Php,Mysql,List,Loops,我将mysql结果列为4个水平和,其中包含以下代码: echo"<div>"; $c = 1; // change to $c = 0 $media = mysql_query("SELECT * FROM " . "$prefix" . "screen where id=\"$id\" order by id desc limit 16"); while ($cms = mysql_fetch_assoc($media)) { if

我将mysql结果列为4个水平
  • ,其中包含以下代码:

        echo"<div>";
        $c = 1; // change to $c = 0 
        $media = mysql_query("SELECT * FROM " . "$prefix" . "screen where id=\"$id\" order by id desc limit 16");
        while ($cms = mysql_fetch_assoc($media)) {
    
          if (!($c%4)) echo ($c!=0 ? "</ul>" : "")."<ul>";
    
            echo "<li><a href=\"#\"><img src=\"#\"></a></li>\n";
    
            $c++;
                }
    
            echo "</ul></div>\n";
    
          for ($cnt=$c;$cnt%4>0;$cnt++);
    
    echo”“;
    $c=1;//更改为$c=0
    $media=mysql\u查询(“从“$prefix.”屏幕中选择*,其中id=\“$id\”按id顺序描述限制16”);
    而($cms=mysql\u fetch\u assoc($media)){
    如果(!($c%4))回显($c!=0?:)。“
      ”; 回声“
    • \n”; $c++; } 回声“
    \n”; 对于($cnt=$c;$cnt%4>0;$cnt++);
    上述代码的HTML输出为:

    <UL>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
    </UL>
    <UL>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
    </UL>
    <UL>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
    </UL>
    <UL>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
        <li><a href=\"#\"><img src=\"#\"></a></li>
    </UL>
    <UL>
        <li><a href=\"#\"><img src=\"#\"></a></li>
    </UL>
    
    这是不正确的。每个
    应包含4个
  • 更新
    我更改了$c=0并删除了top
    现在可以工作了

    在开头设置
    $c=0
    。循环往往是以零为基础的,而模的使用需要这一点


    你的代码也很难读。也许考虑操作符和缩进块之间的空格?

    问题是顶部的$c=1。因为一开始是1,它只会再打印3个(1+1+1+1=4,4%4=0),然后计数为零,现在将打印4。 这个小补丁应该能奏效

    $c = 0;
    $media = mysql_query("SELECT * FROM " . "$config_ccms_prefix" . "screen where id=\"$id\" order by id desc limit 16"); 
    
    while ($cms = mysql_fetch_assoc($media)) { 
        if (!($c % 4))
            echo "<ul>"; 
    
        echo "<li><a href=\"#\"><img src=\"#\"></a></li>\n"; 
    
        if(!($c++ % 4))
            echo "</ul>";
    } 
    echo "</div>\n"; 
    for ($cnt = $c; $cnt % 4 > 0; $cnt++);
    
    $c=0;
    $media=mysql\u query(“SELECT*FROM”。$config\u ccms\u prefix”。“screen where id=\“$id\”order by id desc limit 16”);
    而($cms=mysql\u fetch\u assoc($media)){
    如果(!($c%4))
    回声“
      ”; 回声“
    • \n”; 如果(!($c++%4)) 回声“
    ”; } 回音“\n”; 对于($cnt=$c;$cnt%4>0;$cnt++);

    (请注意,$c在开始时被设置为0,echo和$c++被移动到循环体的末尾)

    我忘记将
    放在顶部了!因此,您的代码不适用于每个
        中的4个
              中的4个
                对不起,我仍然不明白您想要什么。你能发布你想要的HTML输出吗?我发现了问题!顶部不工作后移除
                  。谢谢