note that javascript and PHP CANNOT interact natively on the same page...one
is client side and one is server side.

you can pass variables between the two in an HTTP request, however.

page1.php:

<script type=javascript>
function makeSqlQuery(businesstype,village) {
var sqlQuery;
        sqlQuery = "SELECT * FROM MAIN WHERE BUSINESSTYPE="
                        + businesstype +
                        " AND VILLAGE="
                        + village
location = "php2.php?sqlQuery=" + sqlQuery;
}
</script>
<form name=thisform>
<select name=businesstype>
</select>
<select name=village>
</select>
<input type=button
onclick="makeSqlQuery(thisform.businesstype,thisform.village)">
</form>

--

this is a silly way to do it, however, and you should just pass the
variables themselves and construct and run the query in a new request using
php.

you use the same page with control structures on it.

DanO


-----Original Message-----
From: Michael Hall [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 15, 2001 12:06 PM
To: Matt Davis
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] javascript in PHP statement



> I am new to php and I am wondering if it is possible to use a javascript
> variable in a php statement for example:
>
> // create sql statement
>
>               $sql = "select * from main where businesstype = "consultancy" and
> top.upper.villagename = != "0";";

As far as I know, no. Unless "top.upper.villagename" is a field in your
database and the rest is that field's contents (couldn't be ... too many
unescaped double quotes and semicolons). Nope, SQL statements don't work
like that and can only refer directly to data in a database, not php or
any other variables.

You might consider using if statements something like this:

if ($top.upper.villagename != '0') {
        $sql = "SELECT * FROM main WHERE business = 'consultancy'";
}


Hope this helps

Mick


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to