FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


memberlist SQL





ALostSoul
i have this code for my memberlist...
Code:

<?php
require("connect.php");

$getuser = mysql_query("SELECT * FROM users ORDER BY id DESC")or die("Get User Problem:". mysql_error());
while($username = mysql_fetch_array($getuser)){
$n++;
if($n > 1) { echo ', '; }
echo $username[username];
}
?>




I want to have 3 usergroups....members, admin, and other staff...admin being 1, staff 2, and users 3...so i want to have three of the codes above with the usergroups so i don't have to add them manually except for changing the usergroup...
so i need 3 of these:
Code:

SELECT * FROM users ORDER BY id DESC


but with usergroups 1,2,and 3...
help anyone?
Gundamxxg
you will need to add a field in your database for the usergroups if you havent already. once you have that in there then your code will look like this.

replace this

Code:
$getuser = mysql_query("SELECT * FROM users ORDER BY id DESC")or die("Get User Problem:". mysql_error());


with

Code:


$ug = $_GET['usergroup'];
$getuser = mysql_query("SELECT * FROM users WHERE usergroup = $ug ORDER BY id DESC") or die("get user problem:" . mysql_error());


i added the get value in there so that the links that you have on your member list page would be similar to this

yoursite.com/memberslist.php?usergroup=1 for admin
"" /memberslist.php?usergroup=2 for staff
"" /memberslist.php?usergroup=3 for users.


if you put that in your code everything should work.
ALostSoul
i was hoping to have it on one page...like
<?php
//admin
?>
<br><br>
<?php
//staff
?>
<br><br>
<?php
//regular users
?>

http://www.alostsoul.frih.net/index.php?id=6

that is the user list as i have it now with all the users...and i want to seperate all the users into 3 sections like i said from highest power...admin...to lowest power...users...
Gundamxxg
if you are going to do that, then you will need to do a for each statement as well as add the usergroup number into the database for each person. then in the foreach loop you will put the break tag after each usergroup value.
ALostSoul
i do have a usergroup number and field in my database..admins are 1, staff are 2, and regular users are 2
Gundamxxg
one really fast question, are you wanting them to all be different visible sections all on the same page like


Administration

Admin, Admin, Admin

Staffing


Staff, Staff, Staff

Users

User, User, User

cause if that is the case then just change your order by to

ORDER BY usergroup DESC
ALostSoul
yeah, i know, i got that with this code
Code:

<h2>Memberlist</h2>
<hr><br>
<h3>Admins</h3>
<?php
require("connect.php");

//admin
$getuser = mysql_query("SELECT * FROM users WHERE usergroup='1' ORDER BY id DESC") or die("Get User Problem:". mysql_error());
while($username = mysql_fetch_array($getuser)){
$n++;
if($n > 1) { echo ', '; }
echo $username[username];
}
?>
<br><br>
<h3>Staff</h3>
<?php
//staff
$getuser = mysql_query("SELECT * FROM users WHERE usergroup='3' ORDER BY id DESC") or die("Get User Problem:". mysql_error());
while($username = mysql_fetch_array($getuser)){
$n++;
if($n > 1) { echo ', '; }
echo $username[username];
}
?>
<br><br>
<h3>Other Users</h3>
<?php
//other users
$getuser = mysql_query("SELECT * FROM users WHERE usergroup='2' ORDER BY id DESC") or die("Get User Problem:". mysql_error());
while($username = mysql_fetch_array($getuser)){
$n++;
if($n > 1) { echo ', '; }
echo $username[username];
}
?>
Related topics
Help: SQL error after uploading new files(thread updated)
SLOW UPLOADING AN SQL FILE
have problem on my sql
SQL Basics
SQL Tutorial
Executing a .sql file through PHP
I can't upload my Database SQL script ! Helllppppp!!!!
SQL
SQL
SQL and PHP
Is there such a wsiwyg editor for sql
SQL Server 2000 and MYSQL, pls help me.
Can I create many SQL database by my self
SQL Disk usage?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.