First, let's set up your database.
To keep things simple, we'll create just two tables in your database. We'll call them products and reviews. If you were building a big site with thousands of products in dozens of categories, you would do things very differently, but for the time being let's pretend that you only have a handful of products.
Note: If you're experienced with many-one and many-many database relationships, you might want to do this with joins instead. But I'm trying to keep things simple.
The products table will contain an arbitrary number of fields that contains the data on your products, such as price, name, etc. Once of these fields must be a field called ID. This field must be unique for every product.
The reviews table will contain a few things: the name of the reviewer, the review itself, perhaps an interger from 1-5 if you wish to install a star-based rating system of sorts, and an ID. This ID must be unique for every review, although numbers may be the same as the IDs of your products. The final field in this table will contain a field called PID which corresponds to the product about which this review is written. For example, if you have a digital camera, and its ID is 7, then any reviews about this specific product would have a PID of 7. Note that multiple rows in this table can have the same PID, since multiple reviews can exist for the same product.
Let's display a product
So we'll make a page called showitem.php which will be used every time we wish to view an item on the site. The information on the time will be passed in the URL through GET. That means that the URL will look something like http://www.yoursite.com/showitem.php?PID=7
Your PHP script can then extract the variable from the URL, and run some MySQL queries in order to get the necessary information:
$product_id = $_GET['PID'];
// Do your database connection thing below
// Get the product information from the database
$sql = "SELECT * FROM products WHERE ID=$product_id";
$result = mysql_query($sql);
while ($result_array = mysql_fetch_array($result)) {
$product_name = $result_array['name'];
$product_price = $result_array['price'];
etc......continue for remaining variables
}
// At this point you have all of your variables for your product.
You can display the variables using HTML and some simple echo commands. Just put this text at any point in a page: <?=$product_name?>
That's shorthand for <?PHP echo $product_name; ?>
If you're unfamiliar with what echo does, check out PHP.net- it prints what follows to the page.
once you're done displaying all of your product information on the top of the page, you'll want to run another query that looks like this:
$sql = "SELECT * FROM reviews WHERE PID=$product_id";
/* Remember that we stored $product_id earlier - it's the variable that we got in the URL. */
$result = mysql_query($sql);
while ($result_array = mysql_fetch_array($result)) {
$reviewer_name = $result_array['name'];
$review_text = $result_array['text'];
/* Now here's the cool part. Since we're still within the while loop, we can display something for each of the reviews one at a time. I'm going to display a simple table for each review, but you can put together something more complex if you'd like */
echo "<table>
<tr>
<td>Reviewer:</td>
<td>$reviewer_name</td>
</tr>
<tr>
<td>Review</td>
<td>$review_text</td>
</tr>
</table>";
} // end of while loop
The two code blocks above are the staple of your page. The first one displays the product info - the second one displays the corresponding reviews.
I hope the above makes sense to you. If you have any questions, let me know. If I don't get back to you because I'm 4,000 miles away, I'm sure there are thousands of other members who can answer your question as well.
Good luck,
-Aaron