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

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

You can search multiple tables this way.

<?php
$conn=mysql_connect("localhost","root");
mysql_select_db("test");
if(isset($_POST['submit'])){
	$value1=$_REQUEST['value1'];
	$value2=$_REQUEST['value2'];
	$query1="select * from table1 where column1 like '%$value1%'";
	$result1=mysql_query($query1);
	while($row1=mysql_fetch_array($result1)){
		// fetch the data for query 1
	}
	$query2="select * from table2 where column1 like '%$value2%'";
	$result2=mysql_query($query2);
	while($row2=mysql_fetch_array($result2)){
		// fetch the data for query 2
	}
}
?>
<html>
<body>
<form method="post" action="test.php">
<input type="text" name="value1"><br />
<input type="text" name="value2"><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</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

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.

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.

Here's how'like it goes:

$query="Select * from table1
             LEFT JOIN table2
            USING(id)
             LEFT JOIN table3
             USING(id)
            WHERE id='1'";

something like that.

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

This article has been dead for over six months. Start a new discussion instead.