[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 09-16-2005, 02:11 AM   #1 (permalink)
NamePros Member
 
Join Date: Dec 2004
Posts: 30
51.00 NP$ (Donate)

n0dice is an unknown quantity at this point


Displaying a Catalog

Hey guys,

I'm a designer turned coder and it would seem PHP has finally warmed up to me. One thing I can't figure out is how to display a catalog with multiple columns. Obviously I would need a <tr></tr> every four <td>'s and I can't quite get it working. This is the basic method I've been using thus far.

Code:
	<?
$db = mysql_connect("localhost", "un", "pw"); 
mysql_select_db("db",$db); 
$result = mysql_query("SELECT * FROM catagories ORDER BY od asc",$db); 

while($myrow = mysql_fetch_array($result)) 
{ 

echo "CODE";
 
} 
	
?>
My initial thoughts were that I would need to add something like:

$var = 0 before the while() portion and then $var = $var + 1 at the end, and then throw in the <tr></tr> when $var = multiple of 4 or something to that effect, but again I can't get it to work properly.

Thanks for your time.
n0dice is offline  
Old 09-16-2005, 02:21 AM   #2 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
PHP Code:
<?
$db
= mysql_connect("localhost", "un", "pw");
mysql_select_db("db", $db);

$result = mysql_query("SELECT * FROM catagories ORDER BY od asc",$db);

while(
$myrow = mysql_fetch_array($result))
{
//THe below is what I typically do..
$variable = $myrow["column"];
$variable2 = $myrow["column2"];

echo
$variable . "<br>";
echo
$variable2 . "<br>";
}
    
?>
__________________
Eric is offline  
Old 09-16-2005, 02:34 AM   #3 (permalink)
NamePros Regular
 
dkin69's Avatar
 
Join Date: May 2005
Posts: 358
15.75 NP$ (Donate)

dkin69 has a spectacular aura aboutdkin69 has a spectacular aura about


if I understand correctly he wants it laid out in table form

example

row 1 | row 2 | row 3 | row 4 |
row 5 | row 6 | row 7 | row 8 |

etc
dkin69 is offline  
Old 09-16-2005, 03:09 AM   #4 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Quote:
Originally Posted by dkin69
if I understand correctly he wants it laid out in table form

example

row 1 | row 2 | row 3 | row 4 |
row 5 | row 6 | row 7 | row 8 |

etc
PHP Code:
<?
$db
= mysql_connect("localhost", "un", "pw");
mysql_select_db("db", $db);

$result = mysql_query("SELECT * FROM catagories ORDER BY od asc",$db);

while(
$myrow = mysql_fetch_array($result))
{
//THe below is what I typically do..
$variable = $myrow["column"];
$variable2 = $myrow["column2"];

echo
"<table>
<tr>
<td>$variable</td>
<td>$variable2</td>
</tr>
</table>"
;
}
//Something like that. Lol :p
    
?>
__________________
Eric is offline  
Old 09-16-2005, 03:26 AM   #5 (permalink)
NamePros Regular
 
dkin69's Avatar
 
Join Date: May 2005
Posts: 358
15.75 NP$ (Donate)

dkin69 has a spectacular aura aboutdkin69 has a spectacular aura about


HTML Code:
<?
$db = mysql_connect("localhost", "un", "pw");
mysql_select_db("db", $db);

$result = mysql_query("SELECT * FROM catagories ORDER BY od asc limit 8",$db);
echo '<table>';
while($myrow = mysql_fetch_array($result))
{
//THe below is what I typically do..
$variable = $myrow["column"];
$variable2 = $myrow["column2"];
$variable3 = $myrow["column3"];
$variable4 = $myrow["column4"];

echo "<tr><td>$variable</td><td>$variable2</td><td>$variable3</td><td>$variable4</td></tr>";
} //Something like that. Lol :p
echo '
</table>';    
?> 
There, that should give you two rows, to get more change limit 8 to 16 32 whatever.

Hope it helps
dkin69 is offline  
Old 09-16-2005, 05:41 AM   #6 (permalink)
NamePros Regular
 
moondog's Avatar
 
Join Date: Jun 2004
Posts: 476
3,677.00 NP$ (Donate)

moondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of light


.
__________________
The mass purge has begun.
moondog is offline  
Old 09-16-2005, 11:28 AM   #7 (permalink)
NamePros Regular
 
dkin69's Avatar
 
Join Date: May 2005
Posts: 358
15.75 NP$ (Donate)

dkin69 has a spectacular aura aboutdkin69 has a spectacular aura about


Quote:
Originally Posted by moondog
.
how helpful! lol.
dkin69 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Catalog Website Chanesaw Website Development 0 08-06-2005 08:14 AM
Displaying Content When A Checkbox Is Checked?? TWM Programming 6 07-01-2005 07:58 AM
.cgi displaying as raw html in firefox soloBRIAN Programming 0 05-18-2005 07:19 PM
Keeps displaying eye-related ads :| Ringr Google Adsense 4 04-19-2005 02:47 PM
displaying colums adam_uk Programming 4 07-16-2003 06:43 AM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 08:25 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85