Displaying a Catalog

Spacemail by SpaceshipSpacemail by Spaceship
Watch

n0dice

Established Member
Impact
0
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.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
PHP:
<?
$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>";
} 
	
?>
 
0
•••
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
 
0
•••
dkin69 said:
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:
<?
$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
    
?>
 
0
•••
HTML:
<?
$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
 
0
•••
.
 
0
•••
0
•••

We're social

Spaceship
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back