Padgoi Posted September 6, 2007 Share Posted September 6, 2007 Ok, so the following script is a modification to an IPB board. It's supposed to display how many users are currently viewing a topic from forum view. The modification is working somewhat, however, when displaying how many users are viewing a topic, it says, "%s members viewing" instead of showing the actual number. Any help would be appreciated. //----------------------------------------- // How many users are viewing this? //----------------------------------------- if( $this->ipsclass->vars['ma23-usersviewing_enable'] && strstr( ',' . $this->ipsclass->vars['ma23-usersviewing_perms'] . ',', ',' . $this->ipsclass->member['mgroup'] . ',') && strstr( ',' . $this->ipsclass->vars['ma23-usersviewing_forums'] . ',', ',' . $this->forum['id'] . ',' ) && $topic['state'] != 'link' ) { $cut_off = ($this->ipsclass->vars['au_cutoff'] != "") ? $this->ipsclass->vars['au_cutoff'] * 60 : 900; $time = time() - $cut_off; $this->ipsclass->DB->simple_construct( array( 'select' => 's.member_id, s.member_name, s.member_group, s.id, s.login_type, s.location, s.running_time', 'from' => 'sessions s', 'where' => "s.location_1_type='topic' AND s.location_1_id={$topic['tid']} AND s.running_time > {$time} AND s.in_error=0" ) ); $this->ipsclass->DB->simple_exec(); if( $this->ipsclass->DB->get_num_rows() > 0 ) { $ar_time = time(); $cached = array(); $active = array( 'guests' => 0, 'anon' => 0, 'members' => 0 ); $rows = array( $ar_time => array( 'login_type' => substr($this->ipsclass->member['login_anonymous'],0, 1), 'running_time' => $ar_time, 'id' => 0, 'location' => 'st', 'member_id' => $this->ipsclass->member['id'], 'member_name' => $this->ipsclass->member['members_display_name'], 'member_group' => $this->ipsclass->member['mgroup'] ) ); while ($r = $this->ipsclass->DB->fetch_row() ) { $rows[ $r['running_time'].'.'.$r['id'] ] = $r; } krsort( $rows ); //----------------------------------------- // PRINT... //----------------------------------------- foreach( $rows as $result ) { $last_date = $this->ipsclass->get_time( $result['running_time'] ); if ($result['member_id'] == 0) { $active['guests']++; } else { if (empty( $cached[ $result['member_id'] ] ) ) { $cached[ $result['member_id'] ] = 1; if ($result['login_type'] == 1) { $active['anon']++; } else { $active['members']++; } } } } $total = $active['anon'] + $active['guests'] + $active['members']; $this->ipsclass->lang['usersviewing_prefix'] = sprintf( $this->ipsclass->lang['usersviewing_prefix'], $active['members'], $active['guests'], $active['anon'] ); $this->ipsclass->lang['usersviewing'] = sprintf( $this->ipsclass->lang['usersviewing'], $this->ipsclass->lang['usersviewing_prefix'], $total ); } else { $this->ipsclass->lang['usersviewing_prefix'] = ''; $this->ipsclass->lang['usersviewing'] = ''; } } else { $this->ipsclass->lang['usersviewing_prefix'] = ''; $this->ipsclass->lang['usersviewing'] = ''; } unset( $rows, $cached, $active ); Quote Link to comment Share on other sites More sharing options...
btherl Posted September 6, 2007 Share Posted September 6, 2007 I can offer general help only. That output indicates that you didn't use sprintf() where you should have, OR you didn't provide enough arguments to sprintf(). I would guess this line is the problem: $this->ipsclass->lang['usersviewing'] = sprintf( $this->ipsclass->lang['usersviewing'], $this->ipsclass->lang['usersviewing_prefix'], $total ); Quote Link to comment Share on other sites More sharing options...
Padgoi Posted September 7, 2007 Author Share Posted September 7, 2007 anyone can offer a little more help please? Quote Link to comment Share on other sites More sharing options...
btherl Posted September 7, 2007 Share Posted September 7, 2007 Are you familiar with sprintf()? Quote Link to comment Share on other sites More sharing options...
Padgoi Posted September 10, 2007 Author Share Posted September 10, 2007 no, I'm not very adept at PHP. Quote Link to comment Share on other sites More sharing options...
Azu Posted September 10, 2007 Share Posted September 10, 2007 How did you make all that code if you don't know PHP? Quote Link to comment Share on other sites More sharing options...
btherl Posted September 11, 2007 Share Posted September 11, 2007 Here's some sprintf examples. Basically, sprintf replaces things like %s and %d with variables. $name = 'Bob'; $num_widgets = 5; $message = sprintf('%s has %d widgets', $name, $num_widgets); The replacements are done in the same order as they are written. %s means "string", and %d means "integer". Play around with that a while and get familiar with it, and you will understand the code you posted better! Quote Link to comment Share on other sites More sharing options...
Padgoi Posted September 11, 2007 Author Share Posted September 11, 2007 btherl, thanks, but I'm not really trying to get a better grasp of PHP. To be quite honest, I was just trying to obtain some help to get this script working. Can anyone offer some help that might get this working properly? Quote Link to comment Share on other sites More sharing options...
Azu Posted September 12, 2007 Share Posted September 12, 2007 Here's some sprintf examples. Basically, sprintf replaces things like %s and %d with variables. $name = 'Bob'; $num_widgets = 5; $message = sprintf('%s has %d widgets', $name, $num_widgets); The replacements are done in the same order as they are written. %s means "string", and %d means "integer". Play around with that a while and get familiar with it, and you will understand the code you posted better! Why not just do$name = 'Bob'; $num_widgets = 5; $message = echo"$name has $num_widgets widgets"; ? Quote Link to comment Share on other sites More sharing options...
btherl Posted September 13, 2007 Share Posted September 13, 2007 Because the code the OP is dealing with uses sprintf Not much point teaching him how to use php style substitution when he's modifying code that uses sprintf. Padgoi, I think you've got 2 choices here: 1. Learn enough php to do your own modification 2. Post on the freelancing forum and get someone to do it for you Quote Link to comment Share on other sites More sharing options...
Azu Posted September 13, 2007 Share Posted September 13, 2007 Or ask the person that created the script. Quote Link to comment Share on other sites More sharing options...
TheHeretic Posted September 15, 2007 Share Posted September 15, 2007 No offense, but IPB already has this ability out of the box. If you got this code from ize be careful as a number of posted modifications simply duplicate existing functionality. Be equally careful of installing mods from ize to a production site, a lot of them simply don't work and the authors know about as much php as I do, i.e newbie level. Been waiting over a month on ize for an answer to what is a major issue with an add on module. Which version of IPB are you using? 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.