Two tables:
page ID, domain_ID, page
domain ID, domain
Normally I do this:
$result = mysql_query("SELECT * FROM page"); while ($array = mysql_fetch_array ($result)) {
$newresult = mysql_query ("SELECT * FROM domain WHERE ID = " . $array['domain_ID']);
}
I know there must be a way to do this with just one query... cause right now if I pull out 15 page records, I gotta run 15 queries to get all teh domains... how can I get teh stuff from both tables with one query? Can I?
What you are doing is joining those tables by hand. Here's the normal way to do it:
select * from table1 t1 left join table2 t2 on (t1.id-=t2.id);
Look up joins in the mysql handbook and you'll be set.
Nvrmind, foudn out this works:
SELECT category., logosoftwear. FROM category, logosoftwear WHERE category.logosoftwear_ID = logosoftwear.ID
NOW, the real question, which is faster, my original way, or this way of doing it?
Another question... whats the diff. between a JOIN and what I jus did above?
Actually, the two are the same, just different syntax.
the advantage to the join syntax is that it can support keywords like left or natural, whereas in explicit jon syntax (the one you showed) you can only do joins. for example, if you have a record with id 1 in table1, but no corresponding record in table2, the where table1.id=table2.id will fail to match up that record, but a left join will join it up.