1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Display In Rows

Discussion in 'PHP' started by Linkbait, Oct 3, 2006.

  1. #1
    I have a database that is keeping track of 50 images.
    I want to display the images so that there are 10 rows of 5 images per row.

    So for example:

    Row 1 : IMG1 IMG2 IMG3 IMG4 IMG5
    Row 2 : IMG6 IMG7 IMG8 IMG9 IMG10
    and so on.

    The issue is they have a field that tracks how many times they have been viewed and need to be displayed in order of most views to least. So when I tried using the LIMIT 0, 5 LIMIT 6, 5 and so on, it only ordered those results insted of all of the images in the datase.

    Thanks for the help.
     
    Linkbait, Oct 3, 2006 IP
  2. vdd

    vdd Peon

    Messages:
    34
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    1. Try limit 0,5 limit 5,10 and etc
    2. Make one sql-query that selects ALL images and then use `for` to display images in ROWS
     
    vdd, Oct 3, 2006 IP
  3. Linkbait

    Linkbait Peon

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I dont know what you mean by for and I mentioned that the 0,5 limit does not work for this situation.

    Thanks though.
     
    Linkbait, Oct 3, 2006 IP
  4. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #4
    Try using ORDER BY in sql query before LIMIT.
    i.e. ORDER BY no_views DESC LIMIT 0,5
     
    harsh789, Oct 4, 2006 IP
  5. vdd

    vdd Peon

    Messages:
    34
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    <?
    ...
    echo "<table><tr>";
     $res=sql("select * from table order by field desc;");	
     for ($i=0;$i<mysql_num_rows($res);$i++){
       if ($i%5==0&&$i>0) echo "</tr>\n<tr>";
    	$name=mysql_result($res,$i,'name'); 
      echo "<td>$name $i</td>";
     }
    echo "</table>";
    ...
    
    PHP:
     
    vdd, Oct 4, 2006 IP
  6. mnemtsas

    mnemtsas Super Dud

    Messages:
    497
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Why do you want to limit them? Try selecting them all and ordering them by views. Then have a loop within a loop to display them in a table with 5 cells per row. I have had a little too much wine to tell exactly but I believe that is what vdd is saying by way of code.
     
    mnemtsas, Oct 4, 2006 IP
  7. Linkbait

    Linkbait Peon

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Dont know how do use loops with MySql :)

    vdd, thanks for the code. I will try it ASAP and post back.
     
    Linkbait, Oct 7, 2006 IP
  8. Linkbait

    Linkbait Peon

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    *Update*

    It worked v, thanks!
     
    Linkbait, Oct 7, 2006 IP