/    Sign up×
Community /Pin to ProfileBookmark

JavaScript interact with PHP

Hi,

I have the following situation. I have to make some menu (combo-boxes) or like [URL=http://www.dynamicdrive.com/dynamicindex1/chainedmenu/]this[/URL]. I will select something like Region > County > Town and when I press the Go button I want to show me the locations in Town via PHP like that [B][url]http://www.domain.com/showlocation.php?region=county1&town2=thisarethelocations[/url][/B].
I also need to connect that PHP to a Oracle database that give me this values: regions, counties, towns.
How can I do this ? Is way to difficult ?

Thanks in advance for yours advices.

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@Brooksie155Mar 16.2006 — Assuming your selection boxes, and 'go' button are within a form, and the button is of type submit, e.g.

<FORM action="your_php_file.php" method="POST">

<select name="sel_region">

<option value="1">North</option>

<option value="2">East</option>

<option value="3">South</option>

</select>

[ ... Other list boxes go here]

</form>

you will find that the selected values have been posted to your php file and can be accessed using $_POST[].

region = $_POST['sel_region'];

county = $_
POST['sel_county'];

town = $_POST['sel_town'];

therefor if the user selects 'North' then $_POST['sel_region'] == 1.

etc.
Copy linkTweet thisAlerts:
@djlucsauthorMar 16.2006 — Thanks [B]Brooksie155[/B] but I don't have the php file. Can you give me a link or something that can help me build "your_php_file.php" ?

I'm lost and ... ? any help will be more than appreciated.
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 16.2006 — and it has to be an Oracle dB?
Copy linkTweet thisAlerts:
@djlucsauthorMar 16.2006 — Yes, unfortunelly. The database already exist. I have to use the entries from it. When I select region it will have to show in the next combo-boxe all the region are inserted in the database. Than when I choose a region it will have to read all the counties and so on ...

I really don't know how I'm gonna do that ? ? ? !
Copy linkTweet thisAlerts:
@jogolMar 16.2006 — after the go button was pressed the user is directed to your_php_file.php

in your_php_file.php you would get the selected values with

$region = $_REQUEST['sel_region'];

$county = $_
REQUEST['sel_county'];

$town = $_REQUEST['sel_town'];

then you select the matching entries of your db with a WHERE clause like:

... WHERE region = '$region' AND county = '$county' AND town ='$town'

EDIT: sorry, i overlooked the Oracle thinige....
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 16.2006 — here is an example on how to interact with an oracle database with PHP:

http://www.oracle-base.com/articles/misc/WebScriptingForOracle.php#php
Copy linkTweet thisAlerts:
@djlucsauthorMar 16.2006 — Yeah [B]LiLcRaZyFuZzY[/B] I have found those but thanks a lot for your reply.

Now I still have the problem to do the list.php go to list.php?region=south&first_county=town or ... something like that.

Maybe I'm to tired. ?
Copy linkTweet thisAlerts:
@SheldonMar 16.2006 — That has already been given to you by jogel
Copy linkTweet thisAlerts:
@jogolMar 16.2006 — put the form in a file called form.php or something like that. the form has the action <FORM action="list.php" method="POST">

this means the user goes from form.php to list.php after the submit button has been pressed.

in list.php you get the variables to work with via the code i gave you above...
Copy linkTweet thisAlerts:
@djlucsauthorMar 23.2006 — I try but I don't understand. I use [URL=http://simplythebest.net/scripts/DHTML_scripts/javascripts/javascript_15.html]this[/URL] and [URL=http://javascriptkit.com/script/cut183.shtml]this[/URL] but I want to read the data from a database.

This is my index.php file:[code=php]<FORM action="list.php" method="POST">
<select name="sel_region">
<option value="1">North</option>
<option value="2">East</option>
<option value="3">South</option>
</select>

<select name="sel_county">
<option value="1">County1</option>
<option value="2">County1</option>
<option value="3">County1</option>
</select>
<select name="sel_town">
<option value="1">Town1</option>
<option value="2">Town2</option>
<option value="3">Town3</option>
</select>
<input type="submit" value="GO">
[/code]


list.php is that: [code=php]<?php

$region = $_REQUEST['sel_region'];
$county = $_REQUEST['sel_county'];
$town = $_REQUEST['sel_town'];

?>[/code]


I don't know. Show me where to modify! PLS!
Copy linkTweet thisAlerts:
@SheldonMar 23.2006 — Then you have to query the oriacle databse using those vars.

I dont no about oriacle but with mySQL you would do soething like

[code=php]
$query = "SELECT region,country,town FROM table_name WHERE region = '".$region."' and country = '".$country."' and town = '".$town."' ORDER BY town ASC";
$select = mysql_query($query);
[/code]
×

Success!

Help @djlucs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 1.24,
social: @webDeveloperHQ,
});

legal: ({
terms: of use,
privacy: policy
analytics: Fullres
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: @dert,
tipped: article
amount: 1000 SATS,

tipper: @viney352,
tipped: article
amount: 10 SATS,
)...