/    Sign up×
Community /Pin to ProfileBookmark

Help Search Function using Dropdown List

Hi, I have a scenario, that’s need to be done in php please help me with the code. (consider me a total newbie)

I need to get a value from 2 static drop down lists and pass this on the server then return the result by displaying a static page.

I have 2 static drop down lists that users can choose then hit go. First you select “Property Type” then “Property Location” then the value should be grabbed and sent after clicking GO.

Then it should query with the database on the table “sitelinks” that includes the following columns: ID, Name and Link.

After checking, it should then show another static page as a result.
Below is a sample test of the result:

if ($type == ‘condominium’ && $location == ‘click city’)
display(‘condoclick.php’);
else if ($type == ‘residential’ && $location == ‘unclick city’)
display(‘resunclick.php’);[/CODE]

Thanks in advance!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@sunnychotaiOct 09.2008 — Hi cyberjorge,

Can you paste code sample? If everything is static, then you will need to place the dropdowns within <form> tags and the Submit should use the $_GET method.

Your PHP should grab the values from the dropdown and query them. Depending on the results they will redirect to the relevant page using:

<?

header( "Location: typefilenamehere.php" );

?>[/QUOTE]
Copy linkTweet thisAlerts:
@cyberjorgeauthorOct 10.2008 — Hi sunnychotai,

Thanks for your response!

Here are my codes:

For the 2 dropdown lists and submit button in the index.htm:
<form id="form1" method="post" action="">

<select name="prop_type" size="1" id="prop_type" style="width: 140px;">

<option>- Property Type -</option>

<option>Office</option>

<option>Residential</option>

<option>Condominium</option>

<option>Leisure</option>

</select>

<select name="location" size="1" id="location" style="width: 140px;">
<option>- Location -</option>
<option>City1</option>
<option>City2</option>
<option>Province1</option>
<option>Province2</option>
</select>

</form>

<form id="form2" method="post" action="process.php">

<input type="submit" name="go" id="go" value="GO" />

</form>[/QUOTE]


This is for the process.php, I'm playing around but I know it needs to be corrected:
<?PHP

include('functions/config.php');

db_connect();

$TYPE = isset($_POST['prop_type']) ? $_POST : $_GET;

$LOC = isset($_
POST['location']) ? $_POST : $_GET;

"SELECT * FROM sitelinks";

if ($type == 'Condominium' && $loc == 'City1')
display('condocity1.php');
else if ($type == 'Residential' && $loc == 'Province1')
display('resprov1.php');

?>[/QUOTE]


Please be patient with me as I am really new in php.

Thanks.
Copy linkTweet thisAlerts:
@cyberjorgeauthorOct 10.2008 — Anyone Please?
Copy linkTweet thisAlerts:
@sunnychotaiOct 10.2008 — Hi,

A couple of things to note. The option tags should have an associated value. (as per below). This is what is sent to the PHP tags (not the actual text).

There should only be 1 form. You have two forms and when you click on the button it will only take over what is on form2.

Structure:

1. PHP to do the work

2. HTML form

I tend to assign the values sent from the form into variables and then play around with them. You will need to change the "filename.php" to whatever filename that you are calling this.

<i>
</i>&lt;?php
include('functions/config.php');
db_connect();

// Executes anything in the { } braces if the button with value="go" is clicked in the form below - if not then it will ignore it
if ($_POST['go']) {

// Assigns the POST item values to variables from the form
$type = $_POST['prop_type'];
$loc = $_POST['location'];

// Checks if variables are not equal to nothing
if (($type !="") &amp;&amp; ($loc !="")) {

<i> </i> // I don't think you really need this unless you are doing something with the results from the query
<i> </i> // ---------------------------------------------------------------
<i> </i> $sqlStatement = "SELECT * FROM sitelinks";
<i> </i> $sqlResult = mysql_query($sqlStatement);

<i> </i>if (($type == 'Condominium') &amp;&amp; ($loc == 'City1')) {
<i> </i> include('condocity1.php');
<i> </i> }

<i> </i>if (($type == 'Residential' &amp;&amp; $loc == 'Province1')) {
<i> </i> include('resprov1.php');
<i> </i>}
}
}

?&gt;

&lt;html&gt;
&lt;head&gt;&lt;/head&gt;
&lt;body&gt;
&lt;form id="form1" method="post" action="filename.php"&gt;

&lt;select name="prop_type" id="prop_type" style="width: 140px;"&gt;
&lt;option value=""&gt;- Property Type -&lt;/option&gt;
&lt;option value="Office"&gt;Office&lt;/option&gt;
&lt;option value="Residential"&gt;Residential&lt;/option&gt;
&lt;option value="Condominium"&gt;Condominium&lt;/option&gt;
&lt;option value="Leisure"&gt;Leisure&lt;/option&gt;
&lt;/select&gt;

&lt;select name="location" id="location" style="width: 140px;"&gt;
&lt;option value=""&gt;- Location -&lt;/option&gt;
&lt;option value="City1"&gt;City1&lt;/option&gt;
&lt;option value="City2"&gt;City2&lt;/option&gt;
&lt;option value="Province1"&gt;Province1&lt;/option&gt;
&lt;option value="Province2"&gt;Province2&lt;/option&gt;
&lt;/select&gt;

&lt;input type="submit" name="go" id="go" value="GO" /&gt;
&lt;/form&gt;

&lt;/body
&lt;/html&gt;
Copy linkTweet thisAlerts:
@sunnychotaiOct 10.2008 — Try google - you will find lots of code samples... any more q's then shout.

?

I am not sure why you are querying a database. What is in there? And do you want to do anything with the results?
Copy linkTweet thisAlerts:
@cyberjorgeauthorOct 10.2008 — Hi there,

Thanks for your reply again.

I actually don't know what I am doing honestly. ?

I found those codes after googling, I actually thought I still need to save an index list of my static file locations in MySQL database then query it.

I end up being redundant when in fact I can actually do this all in php.

Thanks a lot for switching the light on for me. I really appreciate it.

Thank you also for mentioning about the form, I just add and add this using dreamweaver. I'm still learning, thanks a lot for people like you who are willing to help.

I will try your code, hopefully will work well my AJAX pages/links.
Copy linkTweet thisAlerts:
@cyberjorgeauthorOct 11.2008 — Hi again [B]sunnychotai[/B],

Just want to thank you, worked like a charm!

Thank you so much!

Need to fix some problem though as the page I'm calling are anchored from AJAX.

Below codes won't work.
include("javascript:showdiv('contentarea'); ajaxpage('index.html#resprov1.html', 'contentarea');void(0)");[/QUOTE]

Will just ask this on a proper section, but if anyone there has solution, please let me know.

Thanks again!
×

Success!

Help @cyberjorge 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 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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