chris_rulez001 Posted July 2, 2007 Share Posted July 2, 2007 hi im trying to make an info center for my own forum and i cant seem to make it so if a user comes online their username is added to the info center, below is how i cant seem to have it: XX staff users, XX members, XX guests, XX hidden users online. staff username, member username do you get how this is going? my code: <?php $host1="fdb1.awardspace.com"; $username1="myusername"; $password1="mypassword"; $database1="mydataabse"; $conn = mysql_connect("$host1","$username1","$password1"); if (!$conn) die ("Could not connect MySQL"); mysql_select_db($database1,$conn) or die ("Could not open database"); $mysql2 = "SELECT * FROM forumusers ORDER BY id DESC LIMIT 1"; $result2=mysql_query($mysql2); $row = mysql_fetch_assoc($result2); /*below here is where i would like the XX staff users, XX members, XX guests, XX hidden users online. staff username, member username*/ ?> can someone help me with this request? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 2, 2007 Share Posted July 2, 2007 Well im going to presume that you have some sort of field which identifies the the different user groups. Lets call it `usertype` for the sake of it. You can then cycle through the results, finding the numbers of each group type and the staff and member's names. <?php $mysql2 = "SELECT * FROM forumusers ORDER BY id DESC LIMIT 1"; $result2=mysql_query($mysql2); $staff = array(); $members = array(); $num_staff = 0; $num_members = 0; $num_guests = 0; $num_hidden = 0; foreach($row = mysql_fetch_assoc($result2)){ $usertype = $row['usertype']; $username = $row['username'];//also assuming you have some field for the username $hidden = $row['hidden'];//and perhaps a separate field for their hidden status if($usertype == "staff" && $hidden != 'hidden'){//this may be a number representing staff rather than the text staff $staff[] = $username; $num_staff++; }elseif($usertype == "member" && $hidden != 'hidden'){ $members[] = $username; $num_members++; } //you get the picture } ?> You would then have the numbers stored in the variables $num_staff etc, and the staff names stored in the array $staff and the members stored in the array $members. Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 Well im going to presume that you have some sort of field which identifies the the different user groups. Lets call it `usertype` for the sake of it. You can then cycle through the results, finding the numbers of each group type and the staff and member's names. <?php $mysql2 = "SELECT * FROM forumusers ORDER BY id DESC LIMIT 1"; $result2=mysql_query($mysql2); $staff = array(); $members = array(); $num_staff = 0; $num_members = 0; $num_guests = 0; $num_hidden = 0; foreach($row = mysql_fetch_assoc($result2)){ $usertype = $row['usertype']; $username = $row['username'];//also assuming you have some field for the username $hidden = $row['hidden'];//and perhaps a separate field for their hidden status if($usertype == "staff" && $hidden != 'hidden'){//this may be a number representing staff rather than the text staff $staff[] = $username; $num_staff++; }elseif($usertype == "member" && $hidden != 'hidden'){ $members[] = $username; $num_members++; } //you get the picture } ?> You would then have the numbers stored in the variables $num_staff etc, and the staff names stored in the array $staff and the members stored in the array $members. ok thanks but how will i do it for guests? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 im getting an error: Parse error: syntax error, unexpected ')' in /home/www/hostsareus.awardspace.co.uk/forum/index.php on line 18 code: <?php $host1="fdb1.awardspace.com"; $username1="myusername"; $password1="mypassword"; $database1="mydatabase"; $conn = mysql_connect("$host1","$username1","$password1"); if (!$conn) die ("Could not connect MySQL"); mysql_select_db($database1,$conn) or die ("Could not open database"); $mysql2 = "SELECT * FROM forumusers ORDER BY id DESC LIMIT 1"; $result2=mysql_query($mysql2); $staff = array(); $members = array(); $num_staff = 0; $num_members = 0; $num_guests = 0; $num_hidden = 0; foreach($row = mysql_fetch_assoc($result2)){ $usertype = $row['usertype']; $username = $row['username'];//also assuming you have some field for the username $hidden = $row['hidden'];//and perhaps a separate field for their hidden status if($usertype == "staff" && $hidden != 0){//this may be a number representing staff rather than the text staff $staff[] = $username; $num_staff++; }elseif($usertype == "member" && $hidden != 1){ $members[] = $username; $num_members++; } //you get the picture } ?> line 18 of this code is the: foreach($row = mysql_fetch_assoc($result2)){ and ive tried taking one of the ) out and it says unexpected { on line 18 Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 2, 2007 Author Share Posted July 2, 2007 bump, i need some help please, can someone help? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 3, 2007 Author Share Posted July 3, 2007 can anyone help me please? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 3, 2007 Author Share Posted July 3, 2007 i need help someone ! Quote Link to comment Share on other sites More sharing options...
Carterhost Posted July 3, 2007 Share Posted July 3, 2007 Not sure if this will work, but try while instead of foreach. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 3, 2007 Share Posted July 3, 2007 Yes, that was entirely my fault. Should have been a while statement. No idea where the foreach came from! Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 3, 2007 Author Share Posted July 3, 2007 ok when i logon to my forum its not showing me as online in the users online section, code: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title> - Home</title> <link rel="stylesheet" href="css/stylesheet.css" /> </head> <body text="000000" bgcolor="F1F1F1" link="003399" vlink="003399" alink="003399"> <?php $host="fdb1.awardspace.com"; // Host name $username1="**"; $password1="**"; $database1="**"; $tbl_name="boards"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <?php $host="fdb1.awardspace.com"; // Host name $username1="**"; $password1="**"; $database1="**"; $tbl_name1="forumusers"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result1=mysql_query($sql1); $rows1 = mysql_fetch_array($result1); ?> <br /> <table border="0" width="92%" cellspacing="0" cellpadding="0" style="border-color:#000000" align="center"> <tr> <td width="100%"> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <tr> <td width="27%" height="50" align="center" bgcolor="F1F1F1" class="welcomebg"> </td> <td width="73%" bgcolor="F1F1F1" class="welcomebg" align="center"> <p><font size="2"> <?php if (!isset($_SESSION['username']) == false) { echo "Welcome, ".$_SESSION['displayname']."<br/>"; } else{ echo "Welcome, Guest, Please <a href='login.php'>Login</a> or <a href='register.php'>Register</a><br/>"; }?> <?php $date = date("l F d, g i a"); echo $date; ?> </font><br /></p> </td> </tr> </table> </td> </tr><tr> <td align="center"> <table width="100%" cellspacing="0" cellpadding="0" align="center"> <tr> <td width="100%" align="center"> <table border="0" width="100%" cellpadding="3" cellspacing="0" align="center"> <tr> <td class="menubg" valign="middle" bgcolor="EFEFEF" align="center"><font size="1"> <a href="index.php">Home</a> <a href="help.php">Help</a> <a href="members.php">Members</a> <a href="view_profile.php">Profile</a><?php if ($_SESSION['username'] == "admin") { echo " <a href='admin.php'>Admin Panel</a>"; }else { echo ""; } ?> <?php if (!isset($_SESSION['username']) == false) { echo " <a href='logout.php'>Logout</a>"; }else { echo " <a href='login.php'>Login</a> <a href='register.php'>Register</a>"; } ?> </font><?php mysql_close(); ?></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> <br /> <center></center><br /> <br /> <table width="92%" cellspacing="0" cellpadding="0" align="center"> <tr> <td valign="top" width="100%"> <br /> <a href="index.php" class="nav">Hosts Are Us Support</a> :: Home <?php while($rows = mysql_fetch_array($result)){ // Start looping table row ?> <br/> <table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="000000" class="bordercolor"> <tr> <td> <table cellpadding="4" cellspacing="1" border="0" width="100%"> <tr> <td class="titlebg" bgcolor="4080B0" colspan="2"> <font class="titletext" color="F1F1F1" size="-1"><b>Board Name</b></font></td> <td class="titlebg" bgcolor="4080B0" width="1%" align="center"><font class="titletext" color="F1F1F1" size="-1"><b> Topics</b></font></td> <td class="titlebg" bgcolor="4080B0" width="1%" align="center"> <font class="titletext" color="F1F1F1" size="-1"><b>Posts</b></font></td> <td class="titlebg" bgcolor="4080B0" width="24%" align="center"> <font class="titletext" color="F1F1F1" size="-1"><b>Last Post</b></font></td> </tr> <tr> <td colspan="5" class="catbg" bgcolor="DADADA" height="18"> <font size="2" class="cattext" color="0E0E0E"><b><?php echo $rows['catogory']; ?></b></font></td> </tr> <tr> <td class="windowbg" bgcolor="EFEFEF" width="8%" align="center" valign="middle"></td> <td class="windowbg2" bgcolor="F6F6F6" align="left" width="66%" valign="top" style="cursor:pointer;" onClick="if(!pb_bubble)location.href='/index.cgi?board=updates';" onMouseOver="mouseOverHighlightCell(this);setWindowStatus('Upgrades / News Board');return true;" onmouseout="mouseOutHighlightCell(this);setWindowStatus('');return true;"> <font size="2"><a href="view_board.php?board=<?php echo $rows['board']; ?>"><?php echo $rows['boardname']; ?></a></font><br/> <font size="1"><?php echo $rows['description']; ?><br/></font></td> <td class="windowbg" bgcolor="EFEFEF" valign="middle" align="center" width="1%"> <font size="2"><? echo $rows['topics']; ?></font></td> <td class="windowbg" bgcolor="EFEFEF" valign="middle" align="center" width="1%"> <font size="2"><? echo $rows['posts']; ?></font></td> <td class="windowbg2" bgcolor="F6F6F6" width="24%" valign="top"> <font size="1"></font></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" class="catbg" bgcolor="DADADA" height="18"><font size="2" class="cattext" color="0E0E0E">Mark All Boards As Read <a href="/index.cgi?action=markallboardsread"></a></font></td> </tr> </table></td> </tr> </table> <br/><br/> <table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="000000" class="bordercolor"> <tr> <td> <table cellpadding="4" cellspacing="1" border="0" width="100%"> <tr> <td bgcolor="4080B0" class="titlebg" align="center" colspan="2"> <font class="text1" color="F1F1F1" size="2"><b>Info Center</b></font></td> </tr> <tr> <td class="catbg" bgcolor="DADADA" colspan="2"> <font size="2" class="cattext" color="0E0E0E"><b>Forum Statistics</b></font></td> </tr> <tr> <td class="windowbg2" bgcolor="F6F6F6" valign="top" align="center"> <table width="98%" cellpadding="3" align="center"><tr><td valign="top" align="left" width="60%"> <font size="1"><br/> Last Updated Topic: by <br/>View the <a href="/index.cgi?action=recent">10 most recent posts</a> of this forum.</font> </td> <td valign="top" align="left" width="40%"> <font size="1"><?php $host1="fdb1.awardspace.com"; $username1="**"; $password1="**"; $database1="**"; $conn = mysql_connect("$host1","$username1","$password1"); if (!$conn) die ("Could not connect MySQL"); mysql_select_db($database1,$conn) or die ("Could not open database"); $mysql2 = "SELECT * FROM forumusers ORDER BY id DESC LIMIT 1"; $result2=mysql_query($mysql2); $row3 = mysql_fetch_assoc($result2); echo "Total Members: <a href='members.php'>".$row3['id']."</a><br/>"; echo "Newest Member: <a href='view_user.php?user=".$row3['username']."'>".$row3['displayname']."</a>"; ?></font></td> </tr> </table></td> </tr> <tr> <td class="catbg" bgcolor="DADADA" colspan="2"> <font size="2" class="cattext" color="0E0E0E"><b>Today's Birthdays</b></font></td> </tr> <tr> <td class="windowbg2" bgcolor="F6F6F6" valign="top"> <table width="98%" cellpadding="3" align="center"> <tr> <td valign="top" align="left"> <font size="1">Nothing Here Yet!<br/></font></td> </tr> </table></td> </tr> <tr> <td class="catbg" bgcolor="DADADA" colspan="2"> <font size="2" class="cattext" color="0E0E0E"><b>Users Online</b></font></td> </tr> <tr> <td class="windowbg2" bgcolor="F6F6F6"><table width="98%" cellpadding="3" align="center"> <tr> <td valign="top" align="left"><font size="1"> <?php $host1="fdb1.awardspace.com"; $username1="**"; $password1="**"; $database1="**"; $conn = mysql_connect("$host1","$username1","$password1"); if (!$conn) die ("Could not connect MySQL"); mysql_select_db($database1,$conn) or die ("Could not open database"); $mysql2 = "SELECT * FROM forumusers ORDER BY id DESC LIMIT 1"; $result2=mysql_query($mysql2); $staff = array(); $members = array(); $num_staff = 0; $num_members = 0; $num_guests = 0; $num_hidden = 0; while($row = mysql_fetch_assoc($result2)){ $usertype = $row['usertype']; $username = $row['username'];//also assuming you have some field for the username $hidden = $row['hidden'];//and perhaps a separate field for their hidden status if($usertype == "staff" && $hidden != 0){//this may be a number representing staff rather than the text staff $staff[] = $username; $num_staff++ }elseif($usertype == "member" && $hidden != 1){ $members[] = $username; $num_members++; } //you get the picture } ?> </font></td> </tr> </table></td> </tr> </table></td> </tr> </table> </td> </tr> </table> <center></center> </body> </html> Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 3, 2007 Author Share Posted July 3, 2007 help someone? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 3, 2007 Author Share Posted July 3, 2007 anyone? help? can someone help? Quote Link to comment Share on other sites More sharing options...
Carterhost Posted July 3, 2007 Share Posted July 3, 2007 Wouldn't it help if you echoed out the data? This <font size="2" class="cattext" color="0E0E0E"><b>Users Online</b></font></td> </tr> <tr> <td class="windowbg2" bgcolor="F6F6F6"><table width="98%" cellpadding="3" align="center"> <tr> <td valign="top" align="left"><font size="1"> <?php $host1="fdb1.awardspace.com"; $username1="**"; $password1="**"; $database1="**"; $conn = mysql_connect("$host1","$username1","$password1"); if (!$conn) die ("Could not connect MySQL"); mysql_select_db($database1,$conn) or die ("Could not open database"); $mysql2 = "SELECT * FROM forumusers ORDER BY id DESC LIMIT 1"; $result2=mysql_query($mysql2); $staff = array(); $members = array(); $num_staff = 0; $num_members = 0; $num_guests = 0; $num_hidden = 0; while($row = mysql_fetch_assoc($result2)){ $usertype = $row['usertype']; $username = $row['username'];//also assuming you have some field for the username $hidden = $row['hidden'];//and perhaps a separate field for their hidden status if($usertype == "staff" && $hidden != 0){//this may be a number representing staff rather than the text staff $staff[] = $username; $num_staff++ }elseif($usertype == "member" && $hidden != 1){ $members[] = $username; $num_members++; } //you get the picture } ?> </font></td> </tr> shows the "Users online", and then a row with nothing in it? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 4, 2007 Author Share Posted July 4, 2007 how would i echo it then? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 4, 2007 Author Share Posted July 4, 2007 help? how do i echo it? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 4, 2007 Author Share Posted July 4, 2007 help please, how do i echo it then? someone please help me? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 5, 2007 Author Share Posted July 5, 2007 can someone help me please? i dont know how to echo it? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 8, 2007 Author Share Posted July 8, 2007 help me someone? how do i echo the data? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 9, 2007 Author Share Posted July 9, 2007 help? i need help, i need to know how to echo it? Quote Link to comment Share on other sites More sharing options...
Carterhost Posted July 9, 2007 Share Posted July 9, 2007 http://us.php.net/echo Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 10, 2007 Author Share Posted July 10, 2007 yes but if i echoed $num_staff it would write 0 and stay 0 code: <?php $mysql2 = "SELECT * FROM forumusers ORDER BY id DESC LIMIT 1"; $result2=mysql_query($mysql2); $staff = array(); $members = array(); $num_staff = 0; $num_members = 0; $num_guests = 0; $num_hidden = 0; foreach($row = mysql_fetch_assoc($result2)){ $usertype = $row['usertype']; $username = $row['username'];//also assuming you have some field for the username $hidden = $row['hidden'];//and perhaps a separate field for their hidden status if($usertype == "staff" && $hidden != 'hidden'){//this may be a number representing staff rather than the text staff $staff[] = $username; $num_staff++; }elseif($usertype == "member" && $hidden != 'hidden'){ $members[] = $username; $num_members++; } //you get the picture } ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 10, 2007 Share Posted July 10, 2007 As you hopefully noticed, i made a lot of assumptions here about the way your database was set up. Could you clarify how you are defining/storing each of the differant user types e.g. your database structure? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 10, 2007 Author Share Posted July 10, 2007 here is my database structure: id tinyint(255) No auto_increment username varchar(255) latin1_swedish_ci password varchar(255) latin1_swedish_ci email varchar(255) latin1_swedish_ci displayname varchar(255) latin1_swedish_ci agesetting varchar(255) latin1_swedish_ci age varchar(255) latin1_swedish_ci gender varchar(255) latin1_swedish_ci emailsetting varchar(255) latin1_swedish_ci banned varchar(255) latin1_swedish_ci user_level varchar(255) latin1_swedish_ci usertype varchar(255) latin1_swedish_ci hidden varchar(255) latin1_swedish_ci ip varchar(255) latin1_swedish_ci Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 10, 2007 Share Posted July 10, 2007 Ok, and are you storing the usertype using text (e.g. staff, member) or by number? And the same for the hidden field? Going back to the code, however, i would suggest that you do check your query was successful with an or die statement, just in case. You also need to be using a while loop rather than a foreach, as was pointed out earlier in the thread. The code inside the loop needs to be finished too - i only started it off for you. You need a few more if statements - for example you need to see if people are hidden as , if i remember correctly, you wanted a separete counter for that. Finally, you need to echo the variables after the while loop: <?php $mysql2 = "SELECT * FROM forumusers ORDER BY id DESC LIMIT 1"; $result2=mysql_query($mysql2) or die(mysql_error());//checking to see if the query was successful $staff = array(); $members = array(); $num_staff = 0; $num_members = 0; $num_guests = 0; $num_hidden = 0; while($row = mysql_fetch_assoc($result2)){//you need a while loop here - my mistake originally $usertype = $row['usertype']; $username = $row['username'];//also assuming you have some field for the username $hidden = $row['hidden'];//and perhaps a separate field for their hidden status if($usertype == "staff" && $hidden != 'hidden'){//this may be a number representing staff rather than the text staff $staff[] = $username; $num_staff++; }elseif($usertype == "member" && $hidden != 'hidden'){ $members[] = $username; $num_members++; } //this is unfinished } echo 'Number of staff online: '.$num_saff.' | Number of members online: '.$num_members; ?> I get the feeling you're wanting someone to do all this for you. If you are, then try the freelance forum. Most people here will help people that help themselves. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.