SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question display output by 3 columns

    hi,i wish to display database fetch result in 3 columns, after that a new row will be created for the following result..

    do you have any idea?

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Run two for() loops. does it make sense?

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kailash Badu View Post
    Run two for() loops. does it make sense?
    thanks! Kailash Badu...

    i just found an tutorial here...
    http://codewalkers.com/tutorialpdfs/tutorial15.pdf

    thanks!

  4. #4
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What a terrible tutorial. Fancy recommending using tables. It will make the layout look like it was formed from Lego blocks rather than 3 columns with independedantly displayed content. And I dont see any need for a for loop.

  5. #5
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bokehman
    What a terrible tutorial. Fancy recommending using tables. It will make the layout look like it was formed from Lego blocks rather than 3 columns with independedantly displayed content. And I dont see any need for a for loop.
    well, will u let us know what is your way of doing it?

  6. #6
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use floated div elements as columns. Data can easily be loaded in one of the following formats:

    147
    258
    369

    123
    456
    789

  7. #7
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I beg to differ, data belongs in tables and while floating divs are an option they aren't the only option.

    cathie, search this forum on modulus and you will get your answer.

  8. #8
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guelphdad View Post
    data belongs in tables
    Tabular data yes but certainly not basic content.

  9. #9
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bokehman
    Use floated div elements as columns. Data can easily be loaded in one of the following formats:
    Yes, but how to fetch data and load them into three inline div elements before going into next block of div elements without using for loop?

  10. #10
    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)
    Quote Originally Posted by cathie View Post
    hi,i wish to display database fetch result in 3 columns, after that a new row will be created for the following result..

    do you have any idea?
    PHP Code:
    $sql "SELECT name FROM people";
    $sql_result mysql_query($sql);

    $i 0;
    echo 
    "<table><tr>";
    while (
    $row mysql_fetch_array($sql_result)) {
      
    //this will be true every 3rd item
      
    if ($i && $i == 0) {
        echo 
    "</tr><tr>";
      }
      echo 
    "<td>" $row['name'] . "</td>";
      
    $i++;
    }
    echo 
    "</tr></table>"

  11. #11
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    PHP Code:
    $sql "SELECT name FROM people";
    $sql_result mysql_query($sql);

    $i 0;
    echo 
    "<table><tr>";
    while (
    $row mysql_fetch_array($sql_result)) {
      
    //this will be true every 3rd item
      
    if ($i && $i == 0) {
        echo 
    "</tr><tr>";
      }
      echo 
    "<td>" $row['name'] . "</td>";
      
    $i++;
    }
    echo 
    "</tr></table>"
    Well Dan, bokehman told he can do this without a for loop. so was curious to know what was his way of doing it.

  12. #12
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this is not such a big deal on displaying in such a way. see my code what i have used to display the 3 columned thumbnail images fetched from database.
    Code:
    <?php
    $rsPics = mysql_query("SELECT * FROM tblpictures WHERE Category='$_REQUEST[CID]' ORDER BY PictureID DESC");
    $numRows = mysql_num_rows($rsPics);
    if($numRows >= 1){
    $trCount = 1;
    ?>
    <tr>
    <?php
    while($rowspic = mysql_fetch_array($rsPics)){
         list($width, $height) = getimagesize("./pictures/$rowspic[PicturePath]");
    	?>
    	<td align="center">
    	<table width="100%" border="0" cellspacing="0" cellpadding="3" class="TableStyle" align="left">
    	<tr>
    	<td><a href="javascript:NullClick();" onClick="window.open('enlarge_picture.php?PID=<?=$rowspic['PictureID']?>&CID=<?=$rowspic['Category']?>&start=<?=$trCount-1?>','A','width=700,height=<?=$height+150?>,align=center,left=200,top=200,scrollbars=yes,top=80,right=150');"><img src="./pictures/thumbnails/<?=$rowspic['PicturePath']?>" width="93" height="60" border="0" /></a></td>
    	</tr>
    	<tr>
    	<td><a href="javascript:NullClick();" onClick="window.open('enlarge_picture.php?PID=<?=$rowspic['PictureID']?>&CID=<?=$rowspic['Category']?>&start=<?=$trCount-1?>','A','width=700,height=<?=$height+150?>,align=center,left=200,top=200,scrollbars=yes,top=80,right=150');" class="A2"><strong><?=$rowspic['PictureName']?></strong></a></td>
    	</tr>
    	</table>
    	</td>
    	<?php
    	if(($trCount % 4) == 0){echo "</tr><tr>";}
    	$trCount++;
    	}
    	?>
    As i have used while loop here. I think we need the any type of loop but i dont say that for loop is only the way. We can do this with any type of loop structure.

  13. #13
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, rajug the whole point was about not using table at all. and besides using while() or if() instead of for() doesn't change anything. lol.

  14. #14
    SitePoint Enthusiast shn's Avatar
    Join Date
    Jan 2006
    Location
    Munich DE
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bokehman View Post
    What a terrible tutorial. Fancy recommending using tables. [...]
    Well, it depends on the actual data, but chances are great that data from a table is tabular data anyway. The way you wrote that makes me think that you think HTML tables are per se bad, which is a common misunderstanding in the current "CSS hype".
    But tables aren't bad, if you place tabular data into them. Using absolutely meaningless div soup on the other hand is.
    Patrick

  15. #15
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kailash Badu View Post
    well, rajug the whole point was about not using table at all. and besides using while() or if() instead of for() doesn't change anything. lol.
    Dan's is a typical table example. It follows the:

    123
    456
    789

    model. Obviously a while loop is needed to fetch the data, no one is disputing that. If you want 3 columns with content displayed vertically using a table things become a problem and the only way around this is to build the table asyncronously.

    3 columns with divs (that read like a newspaper) is pretty easy but the most important part is dividing the content. There are two ways to do this, (1) put the same number of results in each column or (2) divide up the entire content based on its global volume. Option 2 is nicer as it allows all the columns to be completely filled irrespective of the length of any individual result. Have a look at the following example.

    Note: Unlike tables the content in one column does not affect the vertical alignment of the content in the other columns. In this case the data is loaded into paragraphs and then split (as equally as possible) at the nearest paragraph boundry. If the new column didn't start with a heading after the division the most recent heading is reinserted.

    This isn't really a question of right and wrong but more what output do you desire. If you want Lego blocks use a table; if you want a fluid newspaper style columns use this system.


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
  •