/    Sign up×
Community /Pin to ProfileBookmark

plz help me in php

Hi Friends..
I m new on this site and also very new in web development field.Now i m trying to build my first web site wich is data base driven web site. i m facing some problems to build it please help me…

problem #1 is, i have a search page through which user can search entire web site for mobile sets.This page includes drop down lists for search options,Two of them are named “mobile company” and “mobile model” i want that when user select a company for example “NOKIA” then second drop down list named “mobile model” only display NOKIA models and if first selected option was for example SAMSUNG then second list only display SAMSUNG models…how can i do this.

problem #2 is for collecting above information from search page i have a php script as under

****code***
$company=$_POST[‘company’];
$model=$_
POST[‘model’];

$result = mysql_query(“SELECT * FROM contacts WHERE company=’$company’AND model=’$model'”);

**code***

Now problem is that what a have to do when user select “Any Company” and/or “Any model” from search page.
Dear Friends please help me as soon as possible….
Thanks in anticipation..
Tanveer

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@the_treeJun 28.2005 — [code=php]if($_POST['company'] != 'all'){
$company = "company ='$_POST['company']'";
}
else{
$company = '1';
}

if($_POST['model'] != 'all'){
$model = "AND model ='$_POST['model']'";
}
else{
$model = '';
}

$query = "SELECT * FROM 'contacts' WHERE $company $model";
[/code]
Please format your code like that from now on (just use [code=php] [code] or [code=html] tags).

Edit: also, try to use more descriptive subject lines. We know you want help in PHP, as this is the PHP board.
Copy linkTweet thisAlerts:
@ShmohelJun 28.2005 — problem #1 is, i have a search page through which user can search entire web site for mobile sets.This page includes drop down lists for search options,Two of them are named "mobile company" and "mobile model" i want that when user select a company for example "NOKIA" then second drop down list named "mobile model" only display NOKIA models and if first selected option was for example SAMSUNG then second list only display SAMSUNG models...how can i do this.
[/QUOTE]


This cannot be accomplished with PHP since all PHP code executes on the server and just spits out the information to the browser. So, in order to have that dynamic function of chain select drop downs, you will need to use Javascript.

I would first suggest you look through posts in the Javascript forum, then search Google for some answers.
Copy linkTweet thisAlerts:
@the_treeJun 28.2005 — So, in order to have that dynamic function of chain select drop downs, you will need to use Javascript.[/QUOTE]Considering that it'd be a form required to "post" the variables, a simple selection box would be the most obvious solution and wouldn't require any scripting.[code=html]<form action="search.php" method="POST">

<label>Chose a model</label>
<select id="model">
<option value="motorola">Motorola</option>
<option value="nokia">Nokia</option>
<option value="all">All / Any</option>
</select>

<label>Chose a network</label>
<select id="company">
<option value="vodaphone">Vodaphone</option>
<option value="orange">Orange</option>
<option value="all">All / Any</option>
</select>

<input type="submit" value="Find your phone" />

</form>[/code]
Copy linkTweet thisAlerts:
@ShmohelJun 28.2005 — Considering that it'd be a form required to "post" the variables, a simple selection box would be the most obvious solution and wouldn't require any scripting[/QUOTE]

I think he was looking to have the second select box populate with options based upon the selection in the first select box. Which would require Javascript.
Copy linkTweet thisAlerts:
@the_treeJun 28.2005 — Oh, yes. My bad.
Copy linkTweet thisAlerts:
@BeachSideJun 28.2005 — No it can be done in php by simply calling the page itself. If you write the proper query it won't be that slow either.

I just made one for a newspaper here in Atlanta that had almost 500,000 records and it worked excellently on my PIII 650MHZ local dev server when they connected to it to see the mock-up in action. I had times of <2 sec ? of course there was no load on the server except for their connection ?
Copy linkTweet thisAlerts:
@ShmohelJun 28.2005 — No it can be done in php by simply calling the page itself. If you write the proper query it won't be that slow either.

I just made one for a newspaper here in Atlanta that had almost 500,000 records and it worked excellently on my PIII 650MHZ local dev server when they connected to it to see the mock-up in action. I had times of <2 sec ? of course there was no load on the server except for their connection ?[/QUOTE]


So you had the page refresh when an item was selected from a dropdown?
Copy linkTweet thisAlerts:
@BeachSideJun 28.2005 — Sort of... in the action you use $_SERVER['PHP_SELF'] so the page calls itself I did it like that because the drop down menus populated itself with data drawn from the db based upon what the user selected in the previous drop down
Copy linkTweet thisAlerts:
@Tanveer_ArshadauthorJul 02.2005 — Thank u friends,specially 'the tree' ur script really help me. i m replying too late bcoz there was a big problem with my telephone company so i cant connect.

thanks aganin guys
×

Success!

Help @Tanveer_Arshad 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...