Echo users by group in PHP

Hi,

My problem is that when I click a group, I want it to echo all the users in that certain group from the database.

My code so far is:

Groups

<?php include('db.php'); if (isset($_GET["groupID"])) { $sql="SELECT * FROM `group` WHERE groupName <> 'admin' AND groupName <> 'poweruser' AND groupID = " . $_GET["groupID"] ; } else { $sql="SELECT * FROM `group` WHERE groupName <> 'admin' AND groupName <> 'poweruser'" ; } $result=mysql_query($sql,$connection); while($rivi=mysql_fetch_array($result)){ echo "".$line['groupName'].'
'; } mysql_free_result($result); mysql_close($connection); ?>

Any help how to continue from here?

Just taking a whack at it:

[php]

<?php while($rivi=mysql_fetch_array($result)){ echo "".$line['groupName'].'
'; } ?>

[/php]

In the above, you set $rivi to the return value of mysql_fetch_array(), but then you’re using $line in the echo.

Thanks for pointing that out stlewis.

I’ve figured out the code:

[php]

Groups

<?php include('db.php'); if (isset($_GET["groupID"])) { $sql="SELECT `group`.*, `user`.* FROM `user` inner join `group` on group.groupID=user.groupID where group.groupID= " . mysql_real_escape_string($_GET["groupID"]) ; } else { $sql="SELECT * FROM `group` WHERE groupName <> 'admin' AND groupName <> 'poweruser'" ; } $result=mysql_query($sql,$connection); while($line=mysql_fetch_array($result)){ echo "".$line['groupName'].'
'; } mysql_free_result($result); mysql_close($connection); ?>[/php]

Now my problem is that how can I echo out those users by group?

Anyone can help me with this simple problem?

Sponsor our Newsletter | Privacy Policy | Terms of Service