Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Align images only 4 in a row

    Hi,

    I have take the images form the database using the while loop.
    I want to display the images only 4 in a row.

    I have pasted the codings below.




    <?php

    $v_name = JRequest::getString('v_name', '', 'get');
    if ( $v_name )
    {
    $db =& JFactory::getDBO();
    $result = mysql_query( "SELECT Image_Path FROM Project_Design WHERE Project_ID = $db->quote($v_name)")
    or die("SELECT Error: ".mysql_error());
    $num_rows = mysql_num_rows($result);


    echo "<table width=600 border=0>\n";
    $i=0;
    while ($get_info = mysql_fetch_row($result))
    {

    //print "<tr>\n";

    if(($i%2)==0)
    {

    print "<td> <img src=$get_info[0]><br /></img></td>";

    }
    else
    {


    echo "<td> <img src=$get_info[0]></img> </td>";

    }

    //print "</tr>\n";

    $i++;

    }
    echo "</table>\n";
    }


    ?>


    Regards,
    Shoaib.

  • #2
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    614
    Thanks
    48
    Thanked 64 Times in 64 Posts
    You'd probably get more responses if you posted in the PHP forum. Anyway, what you could do is add a counter. You could either have the counter rest at 4 or use a script to check if the number is divisible by 4 evenly and then add a new row accordingly. Or, a new row, since you're using a table.
    EDIT: Actually, since you're already using i as a counter, you could just implement that right into an if statement.
    PHP Code:
    while ($get_info mysql_fetch_row($result)){
    //print "<tr>\n";

    if(($i%2)==0){
        print 
    "<td> <img src=$get_info[0]><br /></img></td>";
    }
    else{
        echo 
    "<td> <img src=$get_info[0]></img> </td>";
    }
    if (
    $i%== && $i != 0){ //NEW CODE, CHECKS IF $i DIVIDED BY 4 HAS A REMAINDER AND IF NOT IT ENDS THE ROW AND ADDS A NEW ROW
        
    echo "</tr><tr>";
    }
    $i++;
    }
    echo 
    "</tr>"//THIS CREATES A ROW END FOR THE LAST ROW AFTER THE WHILE STATEMENT IS COMPLETE 
    Last edited by djh101; 07-30-2010 at 09:20 AM.

  • Users who have thanked djh101 for this post:

    shoaib (07-31-2010)

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Thanks

    Hi,


    Thanks For ur Help. It Works fine.

    Regards,
    Shoaib.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •