PDA

View Full Version : Need help with MySQL syntax


bennystromberg
01-17-2004, 09:25 AM
I want to show information about people (first name, last name, title) on a web page coded in PHP. The problem is that I want different users to see different things. When a person logs in he should be able to see information about the people that works in the same company that he does.
I would like to write like this:
SELECT firstname, lastname, title FROM table WHERE username='logged in user'
But this only lists the single user that is logged on. What should the syntax look like if I want to show information about everybody in the company?
I have a field called company in my db.

Thanks a lot!

Nightfire
01-17-2004, 12:57 PM
Just do SELECT firstname, lastname, title FROM table and then do a while or for loop to list everything, eg


$query = mysql_query($sql);

while($row = mysql_fetch_array($query)){
echo $row['firstname'] . $row['lastname'] . $row['title'];
}

bennystromberg
01-17-2004, 07:59 PM
Thanks for your reply but I donīt think that your code will do the trick because there is people working for other companies in the same table and these people should not be printed.