Forum Moderators: coopster

Message Too Old, No Replies

PHP-MySQL with dreamweaver

         

emma matthews

9:48 am on Jan 18, 2005 (gmt 0)

10+ Year Member



I am trying to create a PHP-MYSQL site with Dreamweaver. I have managed to upload my database of 1000s of products to my web host, and using Dreamweaver created a front end for my database. So, visitors to my website can see each product, and click to see the next one etc(or see as many as I specify, and then click to see the next group etc.)

At the moment to link to a specific product, all I can do is change the url:

[domain.co.uk...]

By changing X and Y, I can make specific products be diplayed.

What I want to do is choose to display a product by a specific field(e.g. Product Name=Widget)

This doesn't work:
[domain.co.uk...]

What is the correct way of achieving this?

dreamcatcher

11:25 am on Jan 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi emma,

So long as you have a field in your database with the product name, you should be able to access it using a query string. Are you familiar with query strings?

In your example, product_name is a variable containing the value of 'widget'. You would use it like this on your query page:

$product_name = $_GET['product_name'];

$query = mysql_query("SELECT FROM table WHERE name = '$product_name' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_object($query);

echo $row->name;

and so on. No need for the limit clause if you have more than one product with the same name. If you do, a loop construct will be needed to fetch all rows.

Hope that helps.

dc

emma matthews

11:59 am on Jan 20, 2005 (gmt 0)

10+ Year Member



Thanks for your help dreamcatcher. I feel I am nearly there, but am missing something small but essential. I am actually very new to all this, so am probably missing something obvious.

I have a database with a table in it called "dvdtable" In this table is a DVD list, which contains 100s of DVDs with fields such as product_name, description etc.

I want to use Dreamweaver to create a page so that when I go to:
[domain.co.uk...] then a page for the film Widget is displayed, or when I go to
[domain.co.uk...] then a page for the film Foo is displayed.

I hope this makes sense.

The dvds.php currently contains the following code:
<?php require_once('Connections/dvdbase.php');?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
mysql_select_db($database_products, $products);
$product_name = $_GET['product_name'];
$query = mysql_query("SELECT * FROM dvdtable WHERE product_name = '$product_name'") or die(mysql_error());
$row = mysql_fetch_object($query);
?>
<HTML>
<HEAD></HEAD>
<BODY>
<?php echo $row['product_name'];?>
<?php echo $row['description'];?>
</BODY>
</HTML>

However, when I look at this page nothing is displayed.

There is nothing wrong with my SQL connection, or anything, as when I use DW default code to generate pages from my database, displaying all products, or X products at a time there is no problem.

Thanks in advance.

dreamcatcher

1:28 pm on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Emma,

You are using mysql_fetch_object, but using the wrong command to display the data. mysql_fetch_object displays the data using a class type operand.

Try changing:

<?php echo $row['product_name'];?>
<?php echo $row['description'];?>

to:

<?php echo $row->product_name;?>
<?php echo $row->description;?>

See if that helps.