473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PHP-MySQL product search tool with list menu

ak1dnar
1,584 Expert 1GB
Hi,
I am developing a PHP web site that uses a search tool in it. I’ll brief it like this,
In the form user will first select Type of the computer (Laptop, desktop or all), then user will select the Brand that he/she expected and also the color or all , if the criteria is matched with the records in the table result should display.

Some times user will select type of the computer and here after by skipping the brand he/she will select the color in that case all brand should display, with specified type and color.

Is any one has completed such a tool pls submit your result back to me.
Pls refer to the Coding HTML / SQL.
Thanks,

email addresses not allowed, removed. - moderator

HTML coding:
[HTML]
<form id="form" name="form" method="post" action = "" >

<select name="type">
<option selected="selected">Select Product Type</option>
<option value="desktop">Desktop</option>
<option value="laptop">Laptop</option>
<option value="all">All Types</option>
</select>

<select name="brand">
<option selected="selected">Select Product Brand</option>
<option value="intel">Intel</option>
<option value="ibm">IBM</option>
<option value="amd">AMD</option>
<option value="toshiba">Toshiba</option>
<option value="all">All Brands</option>

</select>

<select name="color">
<option selected="selected">Select Product Color</option>
<option value="black">Black</option>
<option value="white">White</option>
<option value="Silver">Silver</option>
<option value="all">All Colors</option>
</select>

</form>
[/HTML]

My SQL Code
Expand|Select|Wrap|Line Numbers
  1. create table products
  2. (
  3. p_id int not null primary key,
  4. p_brand char (15) not null,
  5. p_color char (10) not null,
  6. p_type char (10) not null
  7. )
  8.  
  9.  
  10. insert `products` (p_id,p_brand,p_color,p_type)values ('1001','IBM','Black','Laptop')
  11. insert `products` (p_id,p_brand,p_color,p_type)values ('1002','Intel','white','Desktop')
  12. insert `products` (p_id,p_brand,p_color,p_type)values ('1003','Toshiba','Silver','Laptop')
  13. insert `products` (p_id,p_brand,p_color,p_type)values ('1004','Intel','Black','Desktop')
  14. insert `products` (p_id,p_brand,p_color,p_type)values ('1005','AMD','white','Laptop')
  15.  
Jan 13 '07 #1
6 4085
BeRtjh
12
you might want to use
Expand|Select|Wrap|Line Numbers
  1. OnChange="location.php"

[HTML]
<form id="form" name="form" method="post" action = "" OnChange="location.php">

<select name="type">
<option selected="selected">Select Product Type</option>
<option value="desktop">Desktop</option>
<option value="laptop">Laptop</option>
<option value="all">All Types</option>
</select>

<select name="brand">
<option selected="selected">Select Product Brand</option>
<option value="intel">Intel</option>
<option value="ibm">IBM</option>
<option value="amd">AMD</option>
<option value="toshiba">Toshiba</option>
<option value="all">All Brands</option>
</select>

<select name="color">
<option selected="selected">Select Product Color</option>
<option value="black">Black</option>
<option value="white">White</option>
<option value="Silver">Silver</option>
<option value="all">All Colors</option>
</select>

</form>[/HTML]
Jan 17 '07 #2
ronverdonk
4,258 Expert 4TB
How do you intend to let the user start the search by clicking a search or something button, i.e. how do you submit your form to the backend process?

Ronald :cool:
Jan 17 '07 #3
ak1dnar
1,584 Expert 1GB
you might want to use
Expand|Select|Wrap|Line Numbers
  1. OnChange="location.php"

[HTML]
<form id="form" name="form" method="post" action = "" OnChange="location.php">

<select name="type">
<option selected="selected">Select Product Type</option>
<option value="desktop">Desktop</option>
<option value="laptop">Laptop</option>
<option value="all">All Types</option>
</select>

<select name="brand">
<option selected="selected">Select Product Brand</option>
<option value="intel">Intel</option>
<option value="ibm">IBM</option>
<option value="amd">AMD</option>
<option value="toshiba">Toshiba</option>
<option value="all">All Brands</option>
</select>

<select name="color">
<option selected="selected">Select Product Color</option>
<option value="black">Black</option>
<option value="white">White</option>
<option value="Silver">Silver</option>
<option value="all">All Colors</option>
</select>

</form>[/HTML]

Thank you This Not the thing what i need ! I am Not a newbie for PHP.
Jan 19 '07 #4
ak1dnar
1,584 Expert 1GB
How do you intend to let the user start the search by clicking a search or something button, i.e. how do you submit your form to the backend process?

Ronald :cool:
I can pass the HTML data for process it, Sorry I didn't put entire
Form here and also i didn't put my PHP script also.

ok pls take a look at for this.

[PHP]
<?php

$con = mysql_connect('localhost', 'user', 'pwd') or die
("Could not connect to the Database");
mysql_select_db('myDB', $con) or die (mysql_error());

if ($_POST['search'])/* we will assume there is a Button Named search*/
{//main if

$type = $_POST['type'];
$brand = $_POST['brand'];
$color = $_POST['color'];

/* Here I will Get the Form Data to PHP script
Then I want pass it to the MySQL table see my SQL script
*/

/* what should be the most suitable tech for write down the
SQL statement based on the search criteria;
If the user is selecting proper value from the all the menus Like
Laptop , IBM, white No matter I can go for like this;
*/
$sql ="select * from products where
p_type = '$type' AND p_brand = '$brand' AND p_brand = '$brand'
GROUP by p_id Order by p_id asc”;

/* I thing u got the Idea; But what will happen when some one
select this criteria ;
All from Type, IBM , white
How to change my SQL var again and again for this?
*/

$result=mysql_query($sql) or die("Error select statement : " . mysql_error());
if (mysql_num_rows($result) == 0)
{
echo "No Maching Result Found for your Criteria!!!";
}
else
{
// I can show the result as I need Dont worry about this
}

[/PHP]

I didnt debug it some times there might be syntax errors.Thanks
Jan 19 '07 #5
ronverdonk
4,258 Expert 4TB
Too many errors there. This will work. I added the submit form so you can test it out for yourself.

A.PHP:
=====
[html]<form method="post" action="b.php">
type <input type="text" name="type" /><br />
brand<input type="text" name="brand" /><br />
color<input type="text" name="color" /><br />
<input type="submit" value="send it" />
</form>[/html]B.PHP:
======
[php]<?php
$string = array();
$where = "";
if (isset($_POST['type']) AND !empty($_POST['type']) )
$string[] = " p_type = '".$_POST['type']."' ";
if (isset($_POST['brand']) AND !empty($_POST['brand']) )
$string[] = " p_brand = '".$_POST['brand']."' ";
if (isset($_POST['color']) AND !empty($_POST['color']) ) {
$color = $_POST['color'];
$string[] = " p_color = '".$_POST['color']."' ";
}
// setup the WHERE strings
if (!empty($string))
$where = " WHERE ".implode("AND", $string);

$sql="SELECT * FROM products $where GROUP BY p_id ORDER BY p_id asc ";
echo $sql;
?>[/php]
Ronald :cool:
Jan 19 '07 #6
ak1dnar
1,584 Expert 1GB
Too many errors there. This will work. I added the submit form so you can test it out for yourself.

A.PHP:
=====
[html]<form method="post" action="b.php">
type <input type="text" name="type" /><br />
brand<input type="text" name="brand" /><br />
color<input type="text" name="color" /><br />
<input type="submit" value="send it" />
</form>[/html]B.PHP:
======
[php]<?php
$string = array();
$where = "";
if (isset($_POST['type']) AND !empty($_POST['type']) )
$string[] = " p_type = '".$_POST['type']."' ";
if (isset($_POST['brand']) AND !empty($_POST['brand']) )
$string[] = " p_brand = '".$_POST['brand']."' ";
if (isset($_POST['color']) AND !empty($_POST['color']) ) {
$color = $_POST['color'];
$string[] = " p_color = '".$_POST['color']."' ";
}
// setup the WHERE strings
if (!empty($string))
$where = " WHERE ".implode("AND", $string);

$sql="SELECT * FROM products $where GROUP BY p_id ORDER BY p_id asc ";
echo $sql;
?>[/php]
Ronald :cool:
************************************************** *************************************
Thank you very much Ronald.

But,My Search tool is based on List menus.But your one is based on Text Input boxes.

This is Not my requirement anyway thanks, I'll Try to Make it based on your Post.Thank you once again that technique is cool.

************************************************** *************************************
Jan 22 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: lawrence | last post by:
I haven't been able to reach www.php.net for days. Most of the rest of the web is working for me, though I've bad trouble reaching any English sites. Anyone else having trouble?
6
by: the wonderer | last post by:
This is an elementary question, but I've not been able to find the answer, so here goes: I am developing a site using php. I have the html header information in a file that I include in all the...
4
by: Krista | last post by:
Hi everybody, I think my confi has some problems. Can you guys help me to see what is going on? i install Apache2.0.48 and Php4.3.4 in WinXP. I add some codes in httpd(inside apache...
43
by: grz02 | last post by:
Hi, Im an experienced database+software designer and developer, but, unfortunately, anything to do with web-programming and web-systems designs is still a pretty new area to me... (been working...
2
by: gruddo | last post by:
Hi this is my first post. I have two webservers. I can run php code fine on one but not the other. Both webservers can read files only one can write. I have looked around at other posts and they...
8
by: Marcel | last post by:
I have a problem with a PHP page that seems to get executed twice. I am running PHP5 ISAPI on 2003 server. The script is a PHP page with a form. When the form is submitted one record have to...
1
by: ansc1 | last post by:
Hello, I'm new to using php coding. I need help with the following: 1. There is a submit button on the form and is saves information to my database. After clicking on "Save Measurement" it...
1
by: Kesavan | last post by:
I install apache2 in /usr/local/apache2 and install php5 by ./configure --with-apxs2=/usr/local/apache2/bin/ apxs PHP is successfully installed in my system. But now my .php files inside...
0
by: Benjamin Grieshaber | last post by:
Hi, I´m on SuSE 9.3 with xmlrpc-c and xmlrpc-c-devel installed (ver. 0.9.10) I tried to compile php with xmlrpc support and got the following errors: ...
0
by: Patriot89 | last post by:
I have a quick question in reference to php file extenstions... I have code for example like this... This is all located on this site www.ixalliance.com/BHS/Default (This is my nav.php file) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.