studgate Posted August 3, 2007 Share Posted August 3, 2007 I have four tables in my database, offices, members, activities & groups. What I want to do is if the user has a group/activity/office in the database, to show it in his profile. I know it should be an if/else statement but I need some help display the data. Example: Username is jean, and if jean has entered any groups, offices, when jean login into his account, the group name and the office name will show so jean can see and update them. Thanks Guys! Quote Link to comment Share on other sites More sharing options...
mpharo Posted August 3, 2007 Share Posted August 3, 2007 you just need to query for that information for each table and then display it...im not sure what else your asking for? maybe post a little bit of code so we can see what your dillema is?? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 3, 2007 Share Posted August 3, 2007 Your db structure, showing table relationships would be useful too Quote Link to comment Share on other sites More sharing options...
studgate Posted August 3, 2007 Author Share Posted August 3, 2007 just the query will be helpful. basically check the username for each table and if the username is jean, show information. the db structure is simple, users ask for username, address, phone, CREATE TABLE `users` ( `id` int(10) NOT NULL auto_increment, `firstname` varchar(30) NOT NULL default '', `lastname` varchar(30) NOT NULL default '', `email` varchar(50) NOT NULL default '', `phone` varchar(15) default NULL, `country` varchar(30) default NULL, `username` varchar(30) NOT NULL default '', `password` varchar(30) NOT NULL default '', `status` int(1) NOT NULL default '1', `registration_timestamp` int(20) NOT NULL default '0', `email_verify_code` varchar(12) default NULL, UNIQUE KEY `id` (`id`), UNIQUE KEY `username` (`username`), UNIQUE KEY `email` (`email`) );'; the other tables are similar. the username field for each table is filled when the user submit any of the form. Thanks again guys. Quote Link to comment Share on other sites More sharing options...
studgate Posted August 3, 2007 Author Share Posted August 3, 2007 the query is the only thing that I need some help on. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 3, 2007 Share Posted August 3, 2007 As the other tables may or may not have data related to the user, use LEFT JOIN when joining on username.. Quote Link to comment Share on other sites More sharing options...
mpharo Posted August 3, 2007 Share Posted August 3, 2007 <?php $select=mysql_query("SELECT * FROM offices WHERE username='$username' ") or die(mysql_error()); while($sql=mysql_fetch_array($select)) { echo "Username: $sql[username]" . "Offices: $sql[offices]"; } ?> just do the same thing for each table and keep giving each variable a unique name. You can also do it with a more complicated query using joins... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.