Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Five results per line

  1. #1
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755

    Five results per line

    Hi all,

    I'm trying to work out how to make it so I can have 5 cells per line in a table, with the results slotting in. Then when five are filled up, a new row is started.

    Please could anyone help?

    Thanks,
    Mike
    Don't you just love free internet games ?

  2. #2
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    You mean, display the results of a query in columns?

    So it'd be:

    result 1 - result 2 - result 3 - result 4 - result 5

    result 6 - result 7

    etc?
    Stepping On Wires - the new blog

  3. #3
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Exactly Mark
    Don't you just love free internet games ?

  4. #4
    Registered flyingpylon's Avatar
    Join Date
    Sep 2003
    Location
    Fishers, IN USA
    Posts
    144
    Put in a counter where each time a cell is added, the counter is incremented by 1. When it gets to 5, start a new row.

    Conceptually it would look something like this (adapt this for ASP/PHP/whatever):

    i = 0
    <tr>
    begin loop
    if i = 5 then
    </tr><tr>
    i = 0 (reset counter)
    end if
    <td>result</td>
    i = i + 1
    end loop
    </tr>

  5. #5
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    That'll be it, thanks Paul
    Don't you just love free internet games ?

  6. #6
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    I like to do it with division.

    If I was making a table and I wanted it to print out 3 cells to a row all you need to do is put the following code at the end of the loop.

    if(!($i % 3)){
    echo "</tr><tr>";
    }

    For 4 cells to a row change the 3 to a 4, etc.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  7. #7
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Seems easier...

    So do you put that when the main loop has finished, or actually inside the loop? Also, could you tell me what the % on the first line does please?

    Thanks a lot,
    Mike
    Don't you just love free internet games ?

  8. #8
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    You put it inside the loop at the end.

    while mysqlresultsetblahblah{

    echo stuff

    if{
    (what I posted)
    }
    }
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  9. #9
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    The % is the modulus operator.

    $i is the counter variable, you still need to increment it ($i++) at the bottom.

    The modulus operator returns the remainder from division. So it returns the remainder of $i/3. If there is no remainder, then 3 is a factor of $i, hence its time to start a new row.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  10. #10
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    Check out this article for more in php operators.

    http://www.developer.com/lang/php/article.php/938511

    Oddly enough it was written by the woman who did the design for WebsitePublisher.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  11. #11
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Heh, thanks Chris
    Don't you just love free internet games ?

  12. #12
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    I tried it out today, and it kinda worked. Only problem was that it had the first emotion on a seperate line to the rest. To get what I mean, look: http://www.msn-emotions.net/downloads/animal-emotions

    My code is as follows:

    PHP Code:
    for ($y=0$y mysql_num_rows($result2); $y++) {
    $row2 mysql_fetch_assoc($result2);
    echo (
    "<td width=10%>");
    echo (
    "<img src='");
    echo 
    $row2['URL'];
    echo (
    "'></td>");
    if(!(
    $y 5)){
    echo 
    "</tr><tr>";
    }

    Please could someone help?

    Thanks a lot,
    Mike
    Don't you just love free internet games ?

  13. #13
    Registered GCT13's Avatar
    Join Date
    Aug 2003
    Location
    NYC
    Posts
    480
    Perhaps start $y at 1, because at zero it's not doing what you want.

    for ($y=1; $y <= mysql_num_rows($result2); $y++) {
    ....

  14. #14
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    I believe the way you have things setup y = 0 for the first row. Since 0/5 has no remainder a new row is created.

    Try starting Y off as 1.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  15. #15
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Yep, that's done it. Thanks guys
    Don't you just love free internet games ?

Similar Threads

  1. You do have more that one line
    By jamesbph in forum The Marketplace
    Replies: 4
    Last Post: 03-11-2004, 11:03 AM
  2. Porn Results In Non-Porn Keyword Searches
    By cameron in forum General Promotion
    Replies: 3
    Last Post: 02-26-2004, 10:44 AM
  3. Local Rank stuff...
    By chromate in forum Search Engine Optimization
    Replies: 41
    Last Post: 02-07-2004, 03:53 PM
  4. ... any luck serps will update with results from google.nl ?
    By s2kinteg916 in forum Search Engine Optimization
    Replies: 9
    Last Post: 01-30-2004, 06:25 PM
  5. the garbage results of google
    By Kyle in forum Search Engine Optimization
    Replies: 8
    Last Post: 12-02-2003, 09:51 AM

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
  •