How do I write a query to achieve the following:

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SFADuncan
Forum Newbie
Posts: 23
Joined: Mon Aug 11, 2003 5:06 pm
Location: uk

How do I write a query to achieve the following:

Post by SFADuncan »

I wish to extract everything from Web as a result of a username variable I have.

I have three tables:

User (username, password, bizname, etc etc)
Biz (bizname, bizstatus, add1, add2 etc etc)
Web (bizname etc, and other fields)

I have the Username variable (as a result of my login script, which should equal user.username) and wish to extract everything from Web where user.bizname=biz.bizname and then subsequently where biz.bizname=web.bizname.

Simon
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Okay.
How about you select everything from the username row and put bizname into a variable, say $biz. The do an SQL query something like

Code: Select all

SELECT * FROM Biz WHERE bizname = '$biz'
Remember to use [php_man]add_slashes[/php_man]:

Code: Select all

<?php
$biz = addslashes($biz);
?>
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Code: Select all

SELECT
    Web.*
FROM
    User,
    Biz,
    Web
WHERE
    Biz.bizname = User.bizname AND
    Web.bizname = Biz.bizname
I'm unsure about the select clause - I've never used that [table_name].* format but I imagine it should work.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply