tags:

views:

47

answers:

2

i have been trying to learn PHP Repeat Region... i have searched google but came across very complicated code samples, e.g & e.g, i would like if somebody be kind enough to provide a simple code sample... like what i am doing is

i have a query which gets results and makes a list with result

$results = mysql_query("SELECT names,age,nic FROM t_able WHERE state='1'");

<ul>
    // The the targeted repeat region starts here
    <li> 
    //my data  
    </li>
    // The target repeat region ends here
</ul>

i know i can do this with a loop but why bother when repeat region functionality is there...why not learn...

p.s. this question is to make the learning simple and AS it is a programming question don't vote down :) or vote to close it ;p

+2  A: 

Something like that is not enough? I dont think there is simpler without a framework and viewhelpers.

<?php
    $results = mysql_query("SELECT names,age,nic FROM t_able WHERE state='1'");
    ?>
    <ul>
        <?php while($array = mysql_fetch_assoc($results)){ ?>
        <li>
        <?php echo $array['names']; ?>
        </li>
        <?php } ?>
    </ul>
Iznogood
+1  A: 

This is a simple loop, which one usually learns quite early on in programming. You may have heard some strange terminology that's just making this more complex than it needs to be.

// Repeat as long as there is a preceding row
while($row = mysql_fetch_assoc($results))
{
    echo "<li>";
    echo "Names: " . $row["names"]; // Add other data
    echo "</li>";
}
Tim Cooper