PDA

View Full Version : Help with Dreamweaver/PHP/SQL


Derek
10-12-2004, 02:33 AM
I'm playing around with creating a database driven website in Dreamweaver MX 2004 - not something i have done before.

I have search.php with a form and couple menus for the user, and results.php for displaying. It will search MySQL 'bikes' database for MAKE and MODEL.

In search.php, the 2 drop-menu objects in form1 are called 'make' (with values Honda, Kawasaki) and 'model' (with values CBR900, ZZR1100).

The problem arrives with the recordset on results.php
- it works fine if i have sql statement as:
SELECT bikes.make, bikes.model, bikes.style, bikes.engine, bikes.year FROM bikes WHERE bikes.make = 'Honda' AND bikes.model = 'CBR900'

... but when i change it to variables, it wont work:
SELECT bikes.make, bikes.model, bikes.style, bikes.engine, bikes.year FROM bikes WHERE bikes.make = 'varMake' AND bikes.model = 'varModel'

I think the problem is not knowing how to enter the info in the variable box. Have read the help files but it only seems to want to tell me about ASP.NET

I tried
Name:varMake
DefaultValue:%
Run-time Value:#Make# ...but its a no-go

Anyone got an idea here please? :)

JXBURNS
10-12-2004, 03:02 AM
I'm only a very small user of PHP/MYSQL but I would suggest from SQL server knowledge that the variables have to be outside the string of other SQL text.

That is:

"SELECT xxx FROM yyyy WHERE string_variable_name = ' " + variablename + " ' "

so that the parser knows you are referring to variablename not a string called 'variablename'.

John

Corey
10-12-2004, 05:04 AM
OK here they have a sample database call:

http://ca3.php.net/mysql

So you would want to use:

$query="SELECT 'make', 'model', 'style', 'engine', 'year' FROM bikes WHERE make='$varMake' AND model='$varModel'";

Where they have typed:

$query = "SELECT * FROM my_table";

Of course assuming the variables in the example have been assigned values, i.e.:

$varModel="Raleigh";
$varMake="High Roller";

Hope that helps. :)

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

Derek
10-17-2004, 01:32 AM
:)

Thanx for the help guys!