User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 422,602 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,645 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 786 | Replies: 10
Reply
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

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

  #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...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

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

  #2  
Feb 5th, 2008
Can you show us your code ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

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

  #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  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

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

  #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?
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

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

  #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
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

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

  #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  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

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

  #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.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

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

  #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.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Aug 2005
Location: somewhere in time
Posts: 71
Reputation: TopDogger is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

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

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

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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:28 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC