SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need to condition a <table> with a if statment need help.

    PHP Code:
     $query "SELECT shoe.shoename, appetizers.price, shoe.moreinfo 
    FROM shoe
    INNER 
    JOIN shoe_kind 
    ON shoe.kind_id=shoe_kind.kind_id"

    $result mysql_query($query$connection);
    while (
    $row mysql_fetch_array($result)) {
    echo 
    "<table style=\"float:left\">
    <td width=\"150\" style=\"text-align:center;\">" 
    $row['shoename'] . "</td>
    <tr>
    <td height=\"100\" width=\"100\"   style=\"position:relative;\">
    <img src=\"../images/shoesname.jpg\" alt=\"sd\" width=\"97\" height=\"80\"  border=\"1\" style=\"border-color:#FF6600;\" />
    </td></tr>
    <tr>
    <td width=\"5\" height=\"21\" ></td><td>" 
    $row['price'] . "</td>
    </tr>
    <td>" 
    $row['moreinfo'] . "</td>
    </table>"
    ;

    The code above contains a while loop that floats all the elements within that table to the left. Now I want the floated elements to repeat to the left only under the condition that when it repeats four elements to the left to stop and continue but in another <td></td> below the first one example:

    Instead of repeting to the left all the time like this

    - - - - - - - - - - - -

    I want the loop to stop when it repeat four and th en go down again and repeat four more and so on. example.

    - - - -
    - - - -
    - - - -
    - - - -

    Like that.

    Any body can help me?
    Last edited by co.ador; May 9, 2009 at 09:08.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    Would it be possible to change the order in the SQL query? That is by far the simplest solution. Then you can keep your view the way it is and handle that logic outside where the SQL is located.

  3. #3
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You're creating a new row <tr> for each cell. You probably don't want to do that.

    Construct the desired HTML first, then add the PHP code to that.

  4. #4
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guys I floated the <table></table> to the right and it worked

    PHP Code:
    <table style=\"float:right\"> 
    Now I am trying to get a condition within this while loop, when the <td></td> repeats more than four times to the right, then the fifth time comes down and repeats four times and so on until it ends all of the row in the database. That way it won't repeat all of the rows just to the right otherwise it will get endless to the right and it will be very unconfortable for the user to go all the way to the right to see a table.
    Last edited by co.ador; May 8, 2009 at 19:41.


Bookmarks

Posting Permissions

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