Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 25-10-07
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
  Displaying database information in columns

I have a database with products in and I want it to automatically show every product on the page. Now I am able to do this easy enough but what I am struggling to do is that I want the products to be displayed in 3 columns. I can get them to display one under the other easy enough but I want them to be in rows with 3 columns instead.

Can anyone give me a helping hand perlease

PHP Code:
echo("<table>"); 
      
    while(
$row mysql_fetch_array($result)){ 
        if (
$bgcolor == "#F7DF42"){ 
            
$bgcolor "#FFFFFF"
        }else{ 
            
$bgcolor "#F7DF42"
     } 
    echo(
"<tr bgcolor=".$bgcolor.">\n<td>"); 
    echo(
'<a href="../products/' $row["product_code"] . '">' $row["description1"] . '</a>'); 
    echo(
'<img src="' $row["small_image"] . '" alt="' $row["description1"] . ' ' $row["description2"] . '"></a>'); 
    echo(
"</td>\n"); 
    } 

    echo(
"</table>"); 
Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 25-10-07
Registered User
 
Join Date: Sep 2007
Posts: 582
Thanks: 0
Thanked 0 Times in 0 Posts
cyates is an unknown quantity at this point
  Re: Displaying database information in columns

ok what do you want in each column ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 25-10-07
Registered User
 
Join Date: Sep 2007
Posts: 582
Thanks: 0
Thanked 0 Times in 0 Posts
cyates is an unknown quantity at this point
  Re: Displaying database information in columns

ahh .. just go what you mean .. you want 3 columns down the page with teh data repeating..

would you want something like
COL 1 COL2 COL3
PROD1 PROD2 PROD3

or

COL 1 COL2 COL3
PROD1 image DESCRIPTION
PROD2 image DESCRIPTION
PROD3 image DESCRIPTION
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 25-10-07
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
  Re: Displaying database information in columns

Quote:
Originally Posted by cyates View Post
ok what do you want in each column ?
Sort of as above really in the above code. The smallimage, link and description
Once I can get it working in a basic form with that then I can mess around and add more/less stuff to each column.

Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 25-10-07
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
  Re: Displaying database information in columns

Quote:
Originally Posted by cyates View Post
COL 1 COL2 COL3
PROD1 PROD2 PROD3
This is the format I'm after, ta

Sorry if my description wasn't all that clear

Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 25-10-07
Registered User
 
Join Date: Sep 2007
Posts: 582
Thanks: 0
Thanked 0 Times in 0 Posts
cyates is an unknown quantity at this point
  Re: Displaying database information in columns

ahh get you ..

erm ok gimme 2 ticks i'll see what i can do
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 25-10-07
Registered User
 
Join Date: Sep 2007
Posts: 582
Thanks: 0
Thanked 0 Times in 0 Posts
cyates is an unknown quantity at this point
  Re: Displaying database information in columns

ok replace the code you posted with this

and yes you need to include teh first instance of $bgcolor

PHP Code:
$bgcolor "#F7DF42";
echo(
"<table><tr bgcolor='".$bgcolor."'>");  
$i=0;
while(
$row mysql_fetch_array($result)){  
if (
$bgcolor == "#F7DF42"){  
$bgcolor "#FFFFFF";  
}else{  
$bgcolor "#F7DF42";  
}  
echo(
"\n<td>");
echo(
'<a href="../products/' $row["product_code"] . '">' .
$row["description1"] . '</a>');
echo(
'<img src="' $row["small_image"] . '" alt="' $row["description1"] . '
$row["description2"] . '"></a>');
echo(
"</td>\n");
if(
$i==2) {
$i=0;
echo 
"</tr><tr bgcolor='".$bgcolor."'>";
}
$i++;
}  

echo(
"</tr></table>"); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #8 (permalink)  
Old 25-10-07
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
  Re: Displaying database information in columns

Absolutely spot on mate, just what I was after

Mucho thanks, you have actually made my day as I've had a few days of coming back to this to try and get it to work with no positive results

Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 25-10-07
Registered User
 
Join Date: Sep 2007
Posts: 582
Thanks: 0
Thanked 0 Times in 0 Posts
cyates is an unknown quantity at this point
  Re: Displaying database information in columns

no probs mate

any other php / mysql probs pm me as you post as i very rarely check that forum

Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 25-10-07
Registered User
 
Join Date: Sep 2007
Posts: 582
Thanks: 0
Thanked 0 Times in 0 Posts
cyates is an unknown quantity at this point
  Re: Displaying database information in columns

also for the record...

for each additional column you want to create just increase $i==2 ( which is 3 columns )
as nessacary $i==3 ( 4 columns etc etc etc )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links