Searching Multiple tables... Please help me!!!!!

Reply

Join Date: Feb 2008
Posts: 77
Reputation: jino is an unknown quantity at this point 
Solved Threads: 5
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Searching Multiple tables... Please help me!!!!!

 
0
  #1
Feb 5th, 2008
I am new in PHP. I have a form having fields from 3 different tables.. I want to search these 3 tables simultaniously for reporting the information...

1st table personal details.
2nd table services offered.
3rd table payment details.

I want to search each and every fields in these tables simultanioulsy...

Please help me...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Searching Multiple tables... Please help me!!!!!

 
0
  #2
Feb 5th, 2008
Can you show us your code ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 77
Reputation: jino is an unknown quantity at this point 
Solved Threads: 5
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: Searching Multiple tables... Please help me!!!!!

 
0
  #3
Feb 5th, 2008
Thanks for ur reply nav,,

the code is very big upto 550 lines...

How can i post that all here...

I just want to know there is any trick to search multiple tables...

Please help me...
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 561
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Searching Multiple tables... Please help me!!!!!

 
0
  #4
Feb 5th, 2008
You can use the join function in mysql.Could you show us what fields are you trying to get in those tables?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Searching Multiple tables... Please help me!!!!!

 
0
  #5
Feb 5th, 2008
You can search multiple tables this way.
  1. <?php
  2. $conn=mysql_connect("localhost","root");
  3. mysql_select_db("test");
  4. if(isset($_POST['submit'])){
  5. $value1=$_REQUEST['value1'];
  6. $value2=$_REQUEST['value2'];
  7. $query1="select * from table1 where column1 like '%$value1%'";
  8. $result1=mysql_query($query1);
  9. while($row1=mysql_fetch_array($result1)){
  10. // fetch the data for query 1
  11. }
  12. $query2="select * from table2 where column1 like '%$value2%'";
  13. $result2=mysql_query($query2);
  14. while($row2=mysql_fetch_array($result2)){
  15. // fetch the data for query 2
  16. }
  17. }
  18. ?>
  19. <html>
  20. <body>
  21. <form method="post" action="test.php">
  22. <input type="text" name="value1"><br />
  23. <input type="text" name="value2"><br />
  24. <input type="submit" name="submit" value="submit">
  25. </form>
  26. </body>
  27. </html>

There are 2 input fields. Whatever the user enters in 1st input field will search table1 and it searches table2 for 2nd input field.
If this is not what you want, then you have to post your code.
Cheers,
Naveen
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 77
Reputation: jino is an unknown quantity at this point 
Solved Threads: 5
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: Searching Multiple tables... Please help me!!!!!

 
0
  #6
Feb 5th, 2008
Thanks for ur reply,,

But there are more than 40 fields in these 3 tables......

Is there any way of searching them all in a single query...???

regards,
Jino.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Searching Multiple tables... Please help me!!!!!

 
0
  #7
Feb 5th, 2008
Search 3 tables in a single query ? As ryan_vietnow said, you can use joins to join these 3 tables based on a condition and search for the desired fields.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 561
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Searching Multiple tables... Please help me!!!!!

 
0
  #8
Feb 5th, 2008
Here's how'like it goes:

  1. $query="Select * from table1
  2. LEFT JOIN table2
  3. USING(id)
  4. LEFT JOIN table3
  5. USING(id)
  6. WHERE id='1'";

something like that.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 87
Reputation: TopDogger is an unknown quantity at this point 
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: Searching Multiple tables... Please help me!!!!!

 
0
  #9
Feb 5th, 2008
Here is a MySQL cheatsheet that includes examples of various table joins.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 12
Reputation: web_lock is an unknown quantity at this point 
Solved Threads: 1
web_lock web_lock is offline Offline
Newbie Poster

Re: Searching Multiple tables... Please help me!!!!!

 
0
  #10
Feb 5th, 2008
well you could make use of the the join as mentioned . Also if you hae MySQL 5 , the use of views could come in handy in the event of intensive usage. It also helps in performance
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC