Querying two tables in the same sentence

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Querying two tables in the same sentence

Post by JKM »

Hi there!

I want to query two tables. It should just select rows from table xxx and where column='.$_POST['nick'].' from another table. Like this:
- SELECT * FROM presentation where username='.$fetch['nick'].' AND (SELECT * FROM users WHERE activated='1').
- Let's say that this page shouldn't show presentations where the status of $fetch/_POST['nick'] isn't activated (0).
- Both tables got the column 'username'.

Code: Select all

<?php
mysql_connect('xxx','xxx','xxx') or die("mysql error");
mysql_select_db("xxx") or die("mysql error");
$query = mysql_query("SELECT * FROM xxx") or die(mysql_error());
while($fetch = mysql_fetch_array($query)) {?>
    <p>blalba <?php $fetch['blabla']; ?>
<?php
} 
?>
Thanks for any help. Sorry if it's explained bad.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Querying two tables in the same sentence

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
Post Reply