English 中文(简体)
Nest鱼和 lo鱼
原标题:Nested while loop doesn t loop as expected
  • 时间:2012-04-24 06:50:14
  •  标签:
  • php
  • loops

我在洛普时有问题。 它只会一劳永逸。 因此,我只能从第二处获得第一行的价值。 请帮助我表明这一点,我是开端。

<ul id="navbar">

     <?php
     $rel = "SELECT * FROM table1 ORDER BY category";
     $sql=$db->query($rel); 
     while($row = $sql -> fetch_array()){
     ?>

     <li><a href="category.php?id=<?php echo $row[ category_id ];?>"><?php echo $row[ category ];?></a> 

        <ul>

            <?php
            $sel = "SELECT * FROM table2 WHERE category_id=".$row[ category_id ]." ORDER BY subcategory ASC";
            $sql=$db->query($sel);  
            while($row1 = $sql -> fetch_array()){
            ?>

            <li><a href="subcategory.php?id=<?php echo $row1[ subcategory_id ];?>"><?php echo $row1[ subcategory ];?></a></li>

            <?php }?>

        </ul>
    </li>

    <?php }?>

</ul>
最佳回答

页: 1 在第二批中,使用另一个变式卡片识别符号。

问题回答

同样,你将第一个查询结果保留在可变的<代码>$ql上。

$sql=$db->query($rel); 

但随后,在第二次投票之前,你超过了这一变量。

$sql=$db->query($sel);  

宣布新的变量供第二次使用。 Say,$sql2

原因是,你在两次询问中都使用可变的<代码>$ql。 例如,将第二版改为<代码>$ql2。

此外,避免使用这么多的<代码><?php?> tags。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签