Web Hosting Talk







View Full Version : PHP Product Catalog - Can Anyone Help?


tjmaxwell
03-20-2006, 01:28 AM
Hello all,

I'm building a large product review website and would like to simplify page creation by pulling in data from a database. Basically, what I want is something very similar to this:

dcresource.com/reviews/cameralist.php
(sorry, I don't have enough posts apparently to post links)

I want to have a full product table, with links to actual product pages. Most of the information within these product pages will be populated from the database (specifications mainly). I'd like users to be able to narrow down the database by various attributes just like what's done on the demonstration above.

I've searched everything I can think of on Google, I've tried several different database management programs and content management systems, but I simply can't find what I'm looking for here. I've already built the product table in MySQL, I just don't know how to display it the way I want it.

Can anyone suggest some software, or a tutorial, or anything that would help me accomplish this? I'm to the point now where I just want it done and don't want to deal with it anymore. I'm also willing to pay if anyone can do this for me in PHP. In any case, please help! Thanks.

h23a1
03-20-2006, 07:02 AM
What you need to do is learn a language such as PHP, JSP or Perl. Then learn to write the SQL queries needed to pull the information from MySQL.

This web site has a plethora of information for you:

http://www.devshed.com

If you are looking for hired help there's an Employment Requests forum.

dollar
03-20-2006, 07:09 AM
Well if you go the route mentioned by h23a1 it will be a long and painful one, but full of rewards in the end. I know OSCommerce has a reveiw option, and with some heavy modifications you could probably get it to wrok the way you want.

tjmaxwell
03-20-2006, 05:47 PM
Ok, I've figured out how to display a grid of my data from the database. Now, I'm having trouble figuring out how to just display a single field from the database by its ID number (example domain.com/products.php?id=23).

I have a large table that contains the manufacturer, product, model number, price, features, etc. I want to set it up so that on my product page, all the information from that specific field displays. I can then use HTML to make it look nice. My primary key is "id" and it is set to auto_increment. Thanks for any help you can offer.

slack
03-20-2006, 07:28 PM
Well, your query to retrieve a single row based on a single column value would look something like this:

SELECT * FROM products WHERE product_id = 23

If you're using php+mysql, the guts of your code would perform the following tasks:

1) Grab the product id from the query string using the builtin $_GET variable.
2) Do some sort of validation on the input.
3) Connect to the database server and select the appropriate database.
4) Build the query using the validated product id.
5) Execute the query and return the result in an associative array.
6) Close database connection.
7) Spit the results out in your markup.

The following code demonstrates all of the above, but is just an overview and off the top of my head. You'll want to write your own functions or class to handle database operations so that you're not having to duplicate code all over the place in your scripts. (alternatively look for a good php mysql class online) You'll also want to handle failure much more gracefully.

<?php

$product_id = (isset($_GET['product_id'])) ? intval($_GET['product_id']) : 0;

if ($product_id > 0) {
if (!($dblink = mysql_connect('host', 'user', 'password')))
die('Could not connect to db');
if (!mysql_select_db('database_name', $dblink))
die('Could not select database');

$query = "SELECT * FROM products WHERE product_id = $product_id";
if ($result=mysql_query($query, $dblink)) {
if (!($product_info = mysql_fetch_array($result, MYSQL_ASSOC)))
die('Product not found');
mysql_free_result($result);
}
mysql_close($dblink);
}
else
die('Invalid product id');



?>
<html>
<body>
<p>
<?php
echo('Product ID: ' . $product_info['product_id']);
echo('<br />Product Name: ' . $product_info['product_name']);
echo('<br />Model Number: ' . $product_info['model_number']);
?>
</p>
</body>
</html>