Jump to content

Help with criteria search script


DJ Unique

Recommended Posts

Hi Everyone, I'm new here and this is my first post. My PHP skills are very limited and I was wondering if someone could help me with a criteria search script I've been working on. I have a mobile phone database and I have a script that can filter items within one table, but I have information in other tables that I want to include in the search.

 

ok, here is the basic structure of the tables I have in my database:

 

manufacturer_detail

- manufacturer_id (Primary Key)

- manufacturer_detail

- manufacturer_name

- manufacturer_url

 

handset_detail

- handset_detail_id (Primary Key)

- handset_model

- handset_code

- handset_type

- handset_description

- manufacturer_id (child foreign key to manufacturer_id field in the manufacturer_detail table)

 

handset_type

- hanset_type_id

- handset_type

- handset_code (child foreign key to handset_code field in the handset_detaill table)

 

Here is my current search script that I can use to search one of those tables above:

 

search_form.php

<form method="post" action="search_script.php">
Handset Code <input type="text" name="code"/><br/> 
Model<input type="text" name="model" /><br/> 
manufacturer ID<input type="text" name="make" /><br/> 
<input type="submit" value="send it"/> 
</form>

 

search_script.php

<?php

$con = mysql_connect('localhost', 'username', 'password') or die 
("Could not connect to the Database");
mysql_select_db('my_db', $con) or die (mysql_error());

$code = $_POST['code'];
$model = $_POST['model'];
$make = $_POST['make'];

$string = array();
$where = "";
if (isset($_POST['code']) AND !empty($_POST['code']) ) 
  $string[] = " handset_code = '".$_POST['code']."' ";
if (isset($_POST['model']) AND !empty($_POST['model']) ) 
  $string[] = " handset_model = '".$_POST['model']."' ";
if (isset($_POST['make']) AND !empty($_POST['make']) ) {
  $color = $_POST['make'];
  $string[] = " manufacturer_detail_id = '".$_POST['make']."' ";
}
// setup the WHERE strings
if (!empty($string))
  $where = " WHERE ".implode("AND", $string);

$sql="SELECT * FROM handset_detail $where GROUP BY handset_detail_id ORDER BY handset_detail_id asc ";
echo $sql


?> 

 

As you can see, I'm only using one table. I don't know how to include all the tables so that I can do a criteria search for something like...

 

Manufacturer: Nokia

Type: Candy Bar

 

This will allow the user to search for all Nokia handsets that have a Candy Bar handset type. That's using two tables from above. (handset_detail and handset_type).

 

I also want the search form to be drop downs. Can anyone help?

 

 

Link to comment
https://forums.phpfreaks.com/topic/39830-help-with-criteria-search-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.