Results 1 to 6 of 6
  1. #1
    Member bluewaves1's Avatar
    Join Date
    April 12th, 2007
    Location
    Utah
    Posts
    125
    Question Creating a 3 column display with this PHP Script
    I am slowly teaching myself how to use PHP and MYSQL and I am having a lot of fun. I'm also clueless about a lot of things.

    I have this snippet of coding that works for my displaying one long list of product info in one column. I'd like to have it displayed in 2 columns or 3.

    Can anyone tell me how to write this part of the code for that?
    while($row = mysql_fetch_assoc($result))
    {
    extract($row);
    $f_price = number_format($price,2);
    echo "<tr>\n
    <td width='100'><img src='$Thumbnail' border ='0'><br>
    <a href='$Link'>$Name</a><br>
    \$$Price</td>\n
    <td width='350'>$Description</td>\n
    <td width='30'style='text-align: right'></td>\n
    </tr>\n";
    <td width='100'><img src='$Thumbnail' border ='0'><br>
    <a href='$Link'>$Name</a><br>
    \$$Price</td>\n
    <td width='350'>$Description</td>\n
    <td width='30'style='text-align: right'></td>\n
    </tr>\n";
    echo "<tr><td colspan='3'><hr /></td></tr>\n";
    }
    echo "</table></center>\n";

  2. #2
    Member Core's Avatar
    Join Date
    March 16th, 2006
    Location
    Cornfield, Illinois
    Posts
    95
    I would recommend looking into layers instead of tables. I couldn't get tables to do what you're trying to do and had to use layers. If you do try to use layers for this MAKE SURE you nest them inside one another for positioning reasons.

  3. #3
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    I usually count the current row and determine the mod value compared to my desired column count. So for example if I want to have 3 columns and I'm currently on item 6 then I'd do 6 % 3 which returns 0. This means when 6 is divided by 3, the remainder is 0. So I would show the row break at this point. The code would look something like this:

    Code:
    $cur_row = 0;
    while($row = mysql_fetch_assoc($result))
    {
    	$cur_row++;
    
    	extract($row);
    	$f_price = number_format($price,2);
    
    	print "
    		<div style='float: left; width: 150px;'>
    		<img src='$Thumbnail' border ='0'><br>
    		<a href='$Link'>$Name</a><br>
    		$f_price</div>
    	";
    
    	if($cur_row % 3 == 0)
    	{
    		print "<div style='clear: left;'><hr>";
    	}
    }
    I used div's because they're much cleaner than a table.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  4. #4
    Affiliate Manager
    Join Date
    April 12th, 2007
    Location
    DC Metro
    Posts
    76
    I ditto Snib's method - it's the best way to do what you want.

  5. #5
    Member bluewaves1's Avatar
    Join Date
    April 12th, 2007
    Location
    Utah
    Posts
    125
    Wink Where do I find more information about layers?
    Can you direct me to a website that I can learn more about layers and their functions?

    Thank you for your response.

  6. #6
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    Quote Originally Posted by bluewaves1
    Can you direct me to a website that I can learn more about layers and their functions?

    Thank you for your response.
    http://css.maxdesign.com.au/floatuto...troduction.htm

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  7. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Creating GC site with the PHP code
    By Tony1234 in forum GoldenCAN
    Replies: 7
    Last Post: May 5th, 2009, 12:07 AM
  2. Category display not working in dynamic script?
    By writerguy in forum Programming / Datafeeds / Tools
    Replies: 17
    Last Post: January 28th, 2008, 02:49 PM
  3. Creating a Datafeed Script
    By HardwareGeek in forum Programming / Datafeeds / Tools
    Replies: 11
    Last Post: March 26th, 2004, 10:23 AM
  4. PHP/MYSQL Method to Display Merchant Promotions
    By squidnunc in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: January 11th, 2004, 04:36 PM
  5. Replies: 10
    Last Post: February 25th, 2003, 12:00 PM

Posting Permissions

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