Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Jun 2003
    Posts
    1
    Member #
    1739
    I have some information I'm trying to display from a database and I don't really know how to go about doing it(i'm a n00b). This is what I have so far:

    PHP Code:
    $query="SELECT `user_id` FROM `phpbb_user_group` WHERE 1 AND `group_id`= '232' ORDER BY `user_id` ASC"
    $result=mysql_query($query); 

    $num=mysql_numrows($result); 

    mysql_close(); 

    echo 
    "<b><center>Database Output</center></b><br><br>"

    $i=0
    while (
    $i $num) { 

    $user_id=mysql_result($result,$i,"user_id"); 

    echo 
    "<b>$user_id<br>"

    ++
    $i

    This just displays the user_id, which is a number. I'm trying to display the username from the phpbb_users table, but only want it to print the usernames of people who have group_id 232 from the phpbb_user_group table. I hope this makes sense...it can't be that hard. I just can't figure it out.

  2.  

  3. #2
    Junior Member Colicab's Avatar
    Join Date
    Apr 2003
    Posts
    15
    Member #
    1112
    $query="SELECT `user_id`

    thats why your selecting the user numbers from the databse not the user names try having a look for something like user_name and see if that works..

  4. #3
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    PHP Code:
    <?php
    $GroupID
    =232;
    //   USE THIS QUERY...
    $query="SELECT t1.user_id, t2.username
    FROM phpbb_user_group AS t1, phpbb_users AS t2"
    ;
    $query .= " WHERE t1.group_id=" $GroupID " AND t1.user_id = t2.user_id";
    //   OR
    $query="SELECT t2.username FROM phpbb_users AS t2";
    $query .= " INNER JOIN phpbb_user_group AS t1 ON t1.user_id = t2.user_id";
    $query .= " WHERE t1.group_id = ".$GroupID;
    $result=mysql_query($query); 
    $num=mysql_numrows($result); 
    mysql_close(); 
    $i=0
    while (
    $i $num) { 
      
    //CHANGE user_id to user_name
      
    $user_id=mysql_result($result,$i,"[b]user_name[/b]"); 
      echo 
    "<b>$user_id<br>"
      ++
    $i
      }
    ?>
    You're cross referencing two tables. Using the second query is more correct I believe....
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:40 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com