Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spit'n 2 Table

Status
Not open for further replies.

slurpyx

Programmer
Joined
Aug 1, 2002
Messages
59
Location
PH
I am used to this:

$query = "select * from table1";
$lookresult = mysql_query($query);

if(mysql_num_rows($lookresult) > 0) {
while($myrow=mysql_fetch_array($lookresult)){
$no=$myrow["no"];

?> html codes <?
echo $no;
?> html codes <?
}
}

Is there a way to query two or more tables in 1 while statement..

i.e.

$query1 = "select * from table1";
$lookresult1 = mysql_query($query1);

$query2 = "select * from table2";
$lookresult2 = mysql_query($query2);

if(????????????????) > 0) {
while(??????????????????)){
echo qry result 1
echo qry result 2
}
}


is this possible? i am a newbie.. and i am probly talking based on my ignorance.. guys would rly love to get some input on this.. or on howto posbly do this...
 
Yes, this is possible.

But without knowing what it is you're trying to do, it's difficult to advise you further.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
An example:

Table1: contact
id
name
company_id
address
phone
mail

Table2: company
id
name

1 query for 2 tables:

select t1.*, t2.* from contact t1, company t2 where t1.company_id=t2.id

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top