InsaneRhino
12-10-2005, 06:23 PM
Hello all I need some help with some PHP and MySQL code im writing. Basically Im using phpbb forums and what I want to do is have a php page that gets the username of users from the phpbb_users table and then cross references them with those from the phpbb_user_group table. I only need usernames that are in a certain group. phpbb used IDs to see who should be in which group. Let me lay down an exanple:
phpbb_users:
user_id: 1
username: InsaneRhino
user_id: 2
username: Gill Bates
now phpbb_user_group looks like:
group_id: 3
user_id: 1
group_id: 3
user_id 2
etc, this puts user id 1 and 2 into group id 3 which is specified in the phpbb_groups table. So to clarify what I need to do is grab from the database all those that are in group_id 3, but I need to get both their username (field: username) and class (field: class). I then need the code to display this on a page. Here is what I have so far, and it seems to work, but it is only displaying 1 username, not all of them.
$link = mysql_connect( "localhost", "user", "pass" );
mysql_select_db( "db", $link );
$sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Mage' && ug.group_id = 3 ORDER BY u.username");
$mage_sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Mage' && ug.group_id = 3 ORDER BY u.username");
$hunter_sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Hunter' && ug.group_id = 3 ORDER BY u.username");
$priest_sql = mysql_query("SELECT u.username FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Priest' && ug.group_id = 3 ORDER BY u.username");
$warlock_sql = mysql_query("SELECT u.username FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Warlock' && ug.group_id = 3 ORDER BY u.username");
$warrior_sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id AND u.class = 'Warrior' && ug.group_id = 3 ORDER BY u.username");
$shaman_sql = mysql_query("SELECT u.username FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Shaman' && ug.group_id = 3 ORDER BY u.username");
$druid_sql = mysql_query("SELECT u.username FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Druid' && ug.group_id = 3 ORDER BY u.username");
$rogue_sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id AND u.class = 'Rogue' && ug.group_id = 3 ORDER BY u.username");
and then I have:
<?php
while( $row = mysql_fetch_array( $mage_sql ) ) {
Echo($row['username']);
Echo("<BR");
}
?>
which continues ovbviously changing &mage_sql for $hunter_sql or what not.
I really need help with this so a massive thank you to anyone who can help. Oh and I have another quick query. I have a news poster that inserts rows into a table, the problem is that when I put a " in the form it comes out as /" on the website, how can i fix this. Thanks
phpbb_users:
user_id: 1
username: InsaneRhino
user_id: 2
username: Gill Bates
now phpbb_user_group looks like:
group_id: 3
user_id: 1
group_id: 3
user_id 2
etc, this puts user id 1 and 2 into group id 3 which is specified in the phpbb_groups table. So to clarify what I need to do is grab from the database all those that are in group_id 3, but I need to get both their username (field: username) and class (field: class). I then need the code to display this on a page. Here is what I have so far, and it seems to work, but it is only displaying 1 username, not all of them.
$link = mysql_connect( "localhost", "user", "pass" );
mysql_select_db( "db", $link );
$sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Mage' && ug.group_id = 3 ORDER BY u.username");
$mage_sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Mage' && ug.group_id = 3 ORDER BY u.username");
$hunter_sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Hunter' && ug.group_id = 3 ORDER BY u.username");
$priest_sql = mysql_query("SELECT u.username FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Priest' && ug.group_id = 3 ORDER BY u.username");
$warlock_sql = mysql_query("SELECT u.username FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Warlock' && ug.group_id = 3 ORDER BY u.username");
$warrior_sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id AND u.class = 'Warrior' && ug.group_id = 3 ORDER BY u.username");
$shaman_sql = mysql_query("SELECT u.username FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Shaman' && ug.group_id = 3 ORDER BY u.username");
$druid_sql = mysql_query("SELECT u.username FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id && u.class = 'Druid' && ug.group_id = 3 ORDER BY u.username");
$rogue_sql = mysql_query("SELECT * FROM phpbb_users u, phpbb_user_group ug WHERE u.user_id = ug.user_id AND u.class = 'Rogue' && ug.group_id = 3 ORDER BY u.username");
and then I have:
<?php
while( $row = mysql_fetch_array( $mage_sql ) ) {
Echo($row['username']);
Echo("<BR");
}
?>
which continues ovbviously changing &mage_sql for $hunter_sql or what not.
I really need help with this so a massive thank you to anyone who can help. Oh and I have another quick query. I have a news poster that inserts rows into a table, the problem is that when I put a " in the form it comes out as /" on the website, how can i fix this. Thanks