Log in

View Full Version : view active users(show admin different colour from users)



liamallan
03-31-2010, 09:56 AM
i have recently created a 'members list' which shows all registered users, and highlights admin in blue.

here is memberslist.php:

<?
include("include/session.php");
?>
<?php
//process.php
$host="mysql4.freehostia.com";
$username="liaall_users";
$password="********";
$db_name="liaall_users";
$tbl_name="users";

mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select db");
$query = mysql_query("SELECT * FROM `users` ORDER BY username ASC,username") or die(mysql_error());
?>

****HTML HERE****

<?php
while($rows=mysql_fetch_array($query)){
?>
<tr>
<td align="center">
<?php
if($rows['userlevel']=='9'){
echo '<a href="http://www.shiftysplayground.co.cc/userinfo.php?user='.$rows['username'].'"><font color="blue">'.$rows['username'].'</font></a>';
}
else{
echo '<a href="http://www.shiftysplayground.co.cc/userinfo.php?user='.$rows['username'].'">'.$rows['username'].'</a>';
}
?>
</td>
</tr>
<?php
}
?>

****HTML HERE****

i wanted to achieve the same thing with 'view_active.php', which is a different setup from 'memberslist.php'. in order to do this i would need to retrieve data from 2 seperate tables.(select all from table 'active users' and userlevel from table 'users')

here is view_active.php:

<?

$q = "SELECT username FROM ".TBL_ACTIVE_USERS
." ORDER BY username ASC,username";
$result = $database->query($q);
/* Error occurred, return given name by default */
$num_rows = mysql_numrows($result);
if(!$result || ($num_rows < 0)){
echo "Error displaying info";
}
else if($num_rows > 0){
/* Display active users, with link to their info */
echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
echo "<tr><td><font size=\"2\">\n";
for($i=0; $i<$num_rows; $i++){
$uname = mysql_result($result,$i,"username");

echo "<a href=\"userinfo.php?user=$uname\">$uname</a> | ";
}
echo "</font></td></tr></table><br>\n";
}
?>

can anyone help me? your help would be very appreciated! thanx :)

djr33
03-31-2010, 07:53 PM
While it might be possible to get the combined result from MySQL using a very complex query, the general method for this is:
1. Get all active users.
2. Loop through each user:
3. For each user, do a new query and loop up user level, etc.

An outline:
$q = mysql_query('FIND ACTIVE USERS');
foreach ($activeusers as $activeuser) {
$q = mysql_query('FIND USER INFO WHERE `user` = $activeuser;');
}

Of course that's not functional code, but the method should be easy enough to integrate into your system.

Hope that helps.

liamallan
03-31-2010, 09:51 PM
thanx for the reply!!

i have tried what u said but cant seem to get it to work. tried allsorts, problem is, i undone all my work and put the original view_active.php buck up on the server so i have lost it all, to show u where i was.

when i try, it either tells me 'error displaying info' or the page is extremely offset.

liamallan
04-03-2010, 09:20 PM
i been trying to connect to both databases, but anything i try, doesnt work. can anyone show me an example to how i could connect to mutliple databases? any help really appreciated

djr33
04-03-2010, 10:14 PM
Are you actually using multiple databases? Why? Or do you mean multiple tables?

liamallan
04-03-2010, 10:16 PM
sorry, its multiple tables. ('active_users' and 'users')

liamallan
04-06-2010, 10:12 PM
i been playing about with view_active.php, and here is wot i got now:

<?
$host="mysql4.freehostia.com";
$username="liaall_users";
$password="*********";
$db_name="liaall_users";
$tbl_name="users";

mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select db");
$query = mysql_query("SELECT * FROM `users` ORDER BY username ASC,username") or die(mysql_error());

$q = "SELECT username FROM ".TBL_ACTIVE_USERS
." ORDER BY username ASC,username";
$result = $database->query($q);
/* Error occurred, return given name by default */
$num_rows = mysql_numrows($result);
if(!$result || ($num_rows < 0)){
echo "Error displaying info";
}
else if($num_rows > 0){
/* Display active users, with link to their info */
echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
echo "<tr><td><font size=\"2\">\n";
for($i=0; $i<$num_rows; $i++){
$uname = mysql_result($result,$i,"username");
}
while($rows=mysql_fetch_array($query)){
}
if($rows['userlevel']=='9'){
echo "<a href=\"http://www.shiftysplayground.co.cc/userinfo.php?user=$uname\"><font color=\"blue\">$uname</font></a>";
}
else{
echo "<a href=\"userinfo.php?user=$uname\">$uname</a> | ";
}
echo "</font></td></tr></table><br>\n";
}
?>

made a small advance since the last time, which wouldnt display due to something being wrong in the coding, but now it displays the page. although, usernames with 'userlevel' value of 9, arent displayed in blue!

any ideas?