query

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
greasypalm
New php-forum User
New php-forum User
Posts: 6
Joined: Tue May 06, 2003 11:33 am

query

Post by greasypalm » Wed May 07, 2003 5:35 am

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?

Skeletor
New php-forum User
New php-forum User
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio
Contact:

Post by Skeletor » Wed May 07, 2003 6:21 am

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 ***
}
}

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Query exact

Post by ruturajv » Wed May 07, 2003 6:21 am

be specific mate
:o

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests