query

A

Anonymous

Guest
Is it possible to search a database table for info and then take that info and then query a table and then display the results?

if so could you please show me how?
 
You may be able to use something like the following.
1) query and retrieve the value to be tested for in the 2nd query.
2) if that value is not empty, then query against the database for results matching the value.

*** EXAMPLE ***
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM first_table WHERE somefield='somevalue'";
$result = mysql_query($query) or die(mysql_error());
mysql_close();

$row = mysql_fetch_row($result)
if(!empty($row['somefield'])) {
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM second_table WHERE someotherfield='".$row['somefield']."'";
$result = mysql_query($query) or die(mysql_error());
mysql_close();
while ($row = mysql_fetch_array($result)) {
*** do whatever you want w/ result ***
}
}
 
Back
Top