Announcements

The New PHP-Fusion USA
by NetriX - 4 weeks ago
Free Hosting
by NetriX - 2 months ago

Latest Posts

MySql?
by daimonbok - 15 hours ago
Video Infusion 3.2.0
by NetriX - 20 hours ago
Version 9 with php 7
by daimonbok - 7 days ago
Facebook Connect 3.0.0
by daimonbok - 1 week ago
URL shortening in PHP
by jim09 - 1 week ago
PHP-Fusion 9 Extensive Demo
by NetriX - 1 week ago
[FORUM RANKS] Flat
by Homdax - 4 weeks ago
The New PHP-Fusion USA
by NetriX - 4 weeks ago
[GUIDE] Optimize PHP-Fusion Website
by NetriX - 4 weeks ago
[FORUM RANKS] ForumCore
by NetriX - 4 weeks ago

View Thread

Who is here? 1 guest(s)
 Print Thread
Top 5 Shoutbox
Dzonson
This is the shoutbox statistics panel, built in a fairly simple manner.

Download source  Code
<?php

if (!defined("IN_FUSION")) { die("Access Denied"); }
openside ("Top 5 Shoutbox");

$limit = 5;
$result=dbquery("SELECT user_name, user_location, user_status, user_avatar,  user_id, count(user_id) AS shout_count FROM ".DB_SHOUTBOX." INNER JOIN
".DB_USERS." ON shout_name=user_id GROUP BY user_name ORDER BY shout_count DESC LIMIT ".$limit."0");
echo "<table width='100%' cellpadding='0' cellspacing='0'>";
if(dbrows($result)!=0){
while($data=dbarray($result)){
if ($data['user_avatar'] && file_exists(IMAGES."avatars/".$data['user_avatar']))  {
   $img = "<img src='".BASEDIR."images/avatars/".$data['user_avatar']."' class='profile_user_avatar'  align='left' width='40px' height='40px' >";
   }
     else { $img = "<img src='".IMAGES."avatars/noavatar100.png' class='profile_user_avatar'  width='40px' height='40px' >";
   }
      echo "<tr>\n<td class='side-small' align='left'>\n";
      echo "<table><td>".$img."</a></td>\n";
      echo "<td class='side-small'> ".profile_link($data['user_id'], $data['user_name'], $data['user_status'])."<br />Wiadomo?ci [ ".$data['shout_count']." ]<br>\n";
      echo "</td>\n</table></td></tr>\n";
}
}
echo "</table>";
closeside();

?>




[fpnotice=info]I would recommend the application includes[/fpnotice]
Edited by Dzonson on 04-10-2013 23:28
 
afoster
Unless I did not set this up correctly, this panel as written shows the top 50 shouters, not the top 5. In addition, and perhaps just on my site, using ".DB_USERS." and "DB_SHOUTBOX." does not work, I have to change that to fusion36535_shoutbox and fusion 36535_users.
 
Tyler
lol No you set it up perfectly correct. If you take a look at the query you will see the limit variable. $limit is set to 5. However look at the query where $limit is and there is a zero after the variable. So whatever the $limit is it adds a zero. If you set it to 10 you'll get 100 results :P

Find this:
Download source  Code
".$limit."0"




and make it
Download source  Code
".$limit


 
afoster
I realized that the problem was in that line of code, but I deleted the "0" part of it which generated an error msg. I then changed the $limit = 5; to $limit=1; and it listed the top 10 shouters.

Little by little I am learning the code but I have a long way to go.
 
Tyler
Yes, your error code is because you didn't the period.

This an edited version of the code posted by Dzony
Download source  Code
<?php

if (!defined("IN_FUSION")) { die("Access Denied"); }
openside ("Top 5 Shoutbox");

$limit = 5;
$result=dbquery("SELECT user_name, user_location, user_status, user_avatar,  user_id, count(user_id) AS shout_count FROM ".DB_SHOUTBOX." INNER JOIN
".DB_USERS." ON shout_name=user_id GROUP BY user_name ORDER BY shout_count DESC LIMIT ".$limit);
echo "<table width='100%' cellpadding='0' cellspacing='0'>";
if(dbrows($result)!=0){
while($data=dbarray($result)){
if ($data['user_avatar'] && file_exists(IMAGES."avatars/".$data['user_avatar']))  {
   $img = "<img src='".BASEDIR."images/avatars/".$data['user_avatar']."' class='profile_user_avatar'  align='left' width='40px' height='40px' >";
   }
     else { $img = "<img src='".IMAGES."avatars/noavatar100.png' class='profile_user_avatar'  width='40px' height='40px' >";
   }
      echo "<tr>\n<td class='side-small' align='left'>\n";
      echo "<table><td>".$img."</a></td>\n";
      echo "<td class='side-small'> ".profile_link($data['user_id'], $data['user_name'], $data['user_status'])."<br />Wiadomo?ci [ ".$data['shout_count']." ]<br>\n";
      echo "</td>\n</table></td></tr>\n";
}
}
echo "</table>";
closeside();

?>


 
Dzonson
I do not know what the problem is with me all works nicely.
 
afoster
There is not a problem per se...the code displays the top 50 shouters, not the top 5
 
Tyler
@Dzony - You don't even have five members on your site so you wouldn't know the problem.... It show the top 50 not 5. I posted the correct version.
 
skpacman
@Tyler

Your update will work on most MySQL installations, but in some cases it'll throw an error without the ROWSTART set on your limit. here's with the ROWSTART set:

Download source  Code
<?php

if (!defined("IN_FUSION")) { die("Access Denied"); }
openside ("Top 5 Shoutbox");

$limit = 5;
$result=dbquery("SELECT user_name, user_location, user_status, user_avatar,  user_id, count(user_id) AS shout_count FROM ".DB_SHOUTBOX." INNER JOIN
".DB_USERS." ON shout_name=user_id GROUP BY user_name ORDER BY shout_count DESC LIMIT ".$limit.",0");
echo "<table width='100%' cellpadding='0' cellspacing='0'>";
if(dbrows($result)!=0){
while($data=dbarray($result)){
if ($data['user_avatar'] && file_exists(IMAGES."avatars/".$data['user_avatar']))  {
   $img = "<img src='".BASEDIR."images/avatars/".$data['user_avatar']."' class='profile_user_avatar'  align='left' width='40px' height='40px' >";
   }
     else { $img = "<img src='".IMAGES."avatars/noavatar100.png' class='profile_user_avatar'  width='40px' height='40px' >";
   }
      echo "<tr>\n<td class='side-small' align='left'>\n";
      echo "<table><td>".$img."</a></td>\n";
      echo "<td class='side-small'> ".profile_link($data['user_id'], $data['user_name'], $data['user_status'])."<br />Wiadomo?ci [ ".$data['shout_count']." ]<br>\n";
      echo "</td>\n</table></td></tr>\n";
}
}
echo "</table>";
closeside();

?>




Look familiar?

Download source  Code
... LIMIT ".$limit.",0");




You need the comma in order to separate between ROWS and ROWSTART. Dzony must have just typo'd the comma.
Edited by skpacman on 05-07-2013 06:14


There are 10 kinds of people in this world.
Those who understand binary,
and those who don't...
 
spkkris
Fix small error:
Download source  Code
<?php

if (!defined("IN_FUSION")) { die("Access Denied"); }
openside ("Top 5 Shoutbox");
include_once INFUSIONS."shoutbox_panel/infusion_db.php";
$limit = 5;
$result=dbquery("SELECT user_name, user_location, user_status, user_avatar,  user_id, count(user_id) AS shout_count FROM ".DB_SHOUTBOX." INNER JOIN
".DB_USERS." ON shout_name=user_id GROUP BY user_name ORDER BY shout_count DESC LIMIT ".$limit.",0");
echo "<table width='100%' cellpadding='0' cellspacing='0'>";
if(dbrows($result)!=0){
while($data=dbarray($result)){
if ($data['user_avatar'] && file_exists(IMAGES."avatars/".$data['user_avatar']))  {
   $img = "<img src='".BASEDIR."images/avatars/".$data['user_avatar']."' class='profile_user_avatar'  align='left' width='40px' height='40px' >";
   }
     else { $img = "<img src='".IMAGES."avatars/noavatar100.png' class='profile_user_avatar'  width='40px' height='40px' >";
   }
      echo "<tr>\n<td class='side-small' align='left'>\n";
      echo "<table><td>".$img."</a></td>\n";
      echo "<td class='side-small'> ".profile_link($data['user_id'], $data['user_name'], $data['user_status'])."<br />Wiadomo?ci [ ".$data['shout_count']." ]<br>\n";
      echo "</td>\n</table></td></tr>\n";
}
}
echo "</table>";
closeside();

?>



Edited by skpacman on 05-07-2013 06:13
 
Jump to Forum:

Similar Threads

Thread Forum Replies Last Post
Top 10 Web Hosting General Chat 13 05-28-2015 12:23
[PANEL] Top 10 Weblinks [7.02.XX] Code Snippets 22 04-05-2015 16:40
[PANEL] Top 5 Downloads [7.02.XX] Code Snippets 1 01-30-2015 16:38
shoutbox character limit Infusions Support 6 06-17-2013 13:28
Shoutbox refresh [7.02.XX] Panels 3 06-09-2013 01:33


WE RECOMMEND THIS HOST - PHP-Fusion Hosting