Jump to content

[SOLVED] Php table help please


hane

Recommended Posts

I've got it here is the code

 

<?php
//set the number of columns
$columns = 3;
$query = "SELECT * FROM africanskyjewellery_items";
$result = mysql_query($query);

//we add this line because we need to know the number of rows
$num_rows = mysql_num_rows($result);
echo "<table summary='' border='0' width='100%'>\n";

//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $num_rows; $i++) {
    $row = mysql_fetch_array($result);
    if($i % $columns == 0) {
        //if there is no remainder, we want to start a new row
        echo "<tr>\n";
    }
    echo "<td colspan='2'>"; 
	echo "<img src='images/" . $row['africanskyjewellery_items_ref'] . ".jpg' width='150'></a><br />";
    echo "<b>Ref:</b>". $row['africanskyjewellery_items_ref'] ."<br />";
	echo "<b>Price:</b>R" . $row['africanskyjewellery_items_price'] . "<br />"; 
	echo "</td>\n";
    if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
        //if there is a remainder of 1, end the row
        //or if there is nothing left in our result set, end the row
        echo "</tr>\n";
    }
}
echo "</table>\n";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.