Jump to content

PHP Query


amin1982

Recommended Posts

Hey Guys,

 

Need some help with a simple PHP code. I am currently putting together an eccomerce website which sells hats.

 

 

The query works but it presents the results top to bottom all on one page within a table.

 

What I need is for the results to be shown left to right in three columns and the with several rows below. I then want the results to be show across several pages.

 

I've tried doing one or two things but the code ends up being messed up. The code is currently

 

<?php // select the data to print

$query = "SELECT * FROM femalehats ORDER BY name ASC";
$result = mysql_query ($query); // Run the query.
$num = mysql_num_rows($result);

if ($num > 0) { // If it ran OK, display the records.


// Table
echo '<table align="left" cellspacing="2" cellpadding="2">
';
// Fetch and print all the records.
$bg = '#eeeeee'; // set back ground colour of the rows.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bg = ($bg=='#EE2323' ? '#470101' : '#EE2323');
echo '<tr bgcolor="' . $bg . '">

<td width="197" rowspan="4">' . $row['hat_image'] . '</td>
<td width="197">' . $row['Name'] . '</td>
<td width="195" rowspan="4">' . $row['hat_image'] . '</td>
<td width="185">' . $row['Name'] . '</td>
</tr>
<tr>
<td>£' . $row['Cost'] . '</td>
<td>£' . $row['Cost'] . '</td>
</tr>
<tr>
<td><a href="viewhat.php?hat_id=' . $row['hat_id'] . '">View Details</a></td>
<td>View Details </td>
</tr>
<tr>
<td>Add to basket</td>
<td>Add to basket</td>
</tr>';

}

echo '</table>';

mysql_free_result ($result); // mysql_free_result()

} else { // If it did not run OK.
echo '<p class="error">ERROR</p>';
}

mysql_close(); // close the connection
?>

Link to comment
https://forums.phpfreaks.com/topic/44583-php-query/
Share on other sites

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.