开发者

Pulling info from database and dynamically adding them into different divs

This may be a bit of a php n00b question but i've managed to get it working this far and I'm a little bit stuck. I'm pulling 12 images with descriptions out of a database. I want to insert them into a client rotator that has 3 sets of 4. They will be contained in divs called

 clientrotate1, clientrotate2, and clientrotate3 
开发者_JAVA百科respectively. Inside each of those divs I want to have 4 images with classes
 thumb1, thumb2, thumb3, and thumb4 
I am successful in having the images and descriptions pull into clientrotator 1. Where I get stuck is to how to dynamically add the 2nd and 3rd set of data into clientrotator2 and clientrotator3.

Here is my function:

        public function DisplayClientRotator(){

    $result = mysql_query( 'SELECT * FROM project ORDER BY id DESC LIMIT 12' )
    or die("SELECT Error: ".mysql_error());

    $iterator = 1;

    while ($row = mysql_fetch_assoc($result)) {


        echo "<div id='clientrotate1'>";
        echo "<div class='thumb$iterator'>";
        echo "<img style='width: 172px; height: 100px;' src=".$row['photo']." />";
        echo "<div class='transbox'>";

        echo "<div class='thumbtext'>";

        echo $row['campaign'];
        echo "</div>";          
        echo "</div>";
        echo "</div>";
        echo "</div>";
        $iterator++;
    }

Any help or pointers int he right direction would be greatly appreciated!

Thanks so much, Matt


You can do two for loops. This is just an example, not specifically applied to your code:

for( $i=0; $i<3; $i++ )
{
    echo "<div id=clientrotate$i>";
    // etc

    for( $k=0; $k<4; $k++ )
    {
        echo "<div class='thumb$k'>";
        echo "</div>";
    }
    echo "</div>";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜