b_kitty Posted October 2, 2006 Share Posted October 2, 2006 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!!) :) Quote Link to comment Share on other sites More sharing options...
bizerk Posted October 2, 2006 Share Posted October 2, 2006 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted October 2, 2006 Share Posted October 2, 2006 This is an example of the method I usehttp://www.phpfreaks.com/forums/index.php/topic,89842.msg360739.html#msg360739 Quote Link to comment Share on other sites More sharing options...
alpine Posted October 2, 2006 Share Posted October 2, 2006 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted October 2, 2006 Share Posted October 2, 2006 Too many 'WHERE' keywords--> .... WHERE aaa = '123' AND WHERE bbb = '345' Quote Link to comment Share on other sites More sharing options...
alpine Posted October 2, 2006 Share Posted October 2, 2006 Barand - you are as always correct - sorry.I've edited the above code.Not easy writing php whilst changing dipers, feeding, washing and putting 3 kids to sleep at the same time... * Quote Link to comment Share on other sites More sharing options...
b_kitty Posted October 3, 2006 Author Share Posted October 3, 2006 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!! ::) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.