Jump to content

create search from multiple choises!


b_kitty

Recommended Posts

I have a PHP-MYSQL application and i want to create an advanced search. I have 4 tables and i want to make it possible for the user to chose from different fields and to make a search based on each field. the point is that i only know a way in which you check which field isset() end u make a search based on that. for the moment i have 5 fields so i have to make quite a lot combinations if i want to see which fields are set. I' am sure there is another way that i have to learn..can someone help me expand my horizons?!(sorry for being so begginner!!) :)
Link to comment
Share on other sites

Yeah, so you have 4 tables that you want to be searched that are on a MYSQL database. Well okay first make sure to connect to your data base or include(); your database scripts and than just use mysql querys and "if" statements to do the rest. The only time i have ever used isset() is for getting something in $_FILES, $_POST, or $_GET.
for example if you have a form where you want to upload a file you would do:
if(isset($_POST['upload_image']))
{
if($_FILES['imgupload']['name] !=null)
{
$this->*some-type-of-function*(*anyvariablesyouwanttobeincluded*)

so maybe if you define the mysql queries above^ and than make a function where the actual search is occuring you could use an ISSET($_POST['submit']))
$this->search_function['name']['file']['etc']

and than go on from there
Link to comment
Share on other sites

Here is a "lighter" version:
[code]
<?php

$query = "select * from table";

$count = 0;
foreach($_POST as $key => $value)
{
if($count == 0): $qq = " WHERE"; else: $qq = " AND"; endif;
if(!empty($value)): $query .= "$qq $key = '$value'"; endif;
$count++;
}
$query .= " order by id desc";

$sql = mysql_query($query) or die(mysql_error());

?>
[/code]
This is dependant that you name your formfield name the same as your table field-names
Link to comment
Share on other sites

I've got the point and i appreciate all the help but the point is that as i mentioned i have to gather information from different tables. For example..3 tables, A, B and C where B holds primary keys of A and C. now if i make a search from fields of table A then i have to search on table B based on A's ID and then in table C from C's ID in B. if i search with a field from C than it is the viceversa. so..now i am lost....:)))))..i don't know if i made the point but i tried to figure out how to build this search page that goes through 4 tables and i couldn't!!! If anyone understood what i meant...the help ME!! ::)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.