View Full Version : foreach doesnt work with IE
emath
05-15-2013, 06:55 PM
I made this script : ( in a hook )
if ($_REQUEST['do'] == 'rqusers' AND $vbulletin->options['active_users_onoff'] AND isset($activeusers) )
{
$first=true;
foreach ( $activeusers as $row ) {
if ( $first ) {
$first = false;
$str = "<li><a class=\"username\" href=\" \"> " . $row["musername"] . "</a></li>"; }
else {
$str .= ", <li><a class=\"username\" href=\" \"> " . $row["musername"] . "</a></li>"; }
}
echo "<p>" . construct_phrase($vbphrase['users_currently_browsing_x_y_z'], $totalonline, $numberregistered, $numberguest) . "</p><ol class=\"commalist\">" . $str . "</ol>" ;
exit;
}
though, on IE, and only IE this doesnt work ( it doesnt through the IF .. )
if i take off the AND isset($activeusers) then i get the error :
Invalid argument supplied for foreach()
any ideas with this ? i tried to do as $key => $value
but it didnt work, again this only happening with IE, with CHROME and FIREFOX everything works great.
nhawk
05-15-2013, 07:10 PM
PHP isn't a client side language, it's server side. So if it works with FF or any other browser, it will work with IE.
What hook did you use?
Where is $activeusers being populated?
Is $activeusers an array?
emath
05-15-2013, 07:21 PM
the hook is showthread_complete .
all im saying, this is what happening . FF and Chrome works well, on IE i get the above error message ( if the isset() is not stated also at the IF condition ) .
$activeusers is an array defined on the showthread.php file .
nhawk
05-15-2013, 07:40 PM
I just tested your code, but to do so I had to remove your if condition because there's no DO condition like that on my system and there's no 'active_users_onoff' that I know of in a standard vB4 install.
So I ended up testing this...
$first=true;
foreach ( $activeusers as $row ) {
if ( $first ) {
$first = false;
$str = "<li><a class=\"username\" href=\" \"> " . $row["musername"] . "</a></li>"; }
else {
$str .= ", <li><a class=\"username\" href=\" \"> " . $row["musername"] . "</a></li>"; }
}
echo "<p>" . construct_phrase($vbphrase['users_currently_browsing_x_y_z'], $totalonline, $numberregistered, $numberguest) . "</p><ol class=\"commalist\">" . $str . "</ol>" ;
exit;
It worked fine with IE.
The other question I have is why not just use the 'Show Users Browsing Threads' option that's built in to vB?
emath
05-15-2013, 07:53 PM
whats the 'Show Users Browsing Threads' option?
nhawk
05-15-2013, 07:57 PM
It does exactly what you're doing with your code. It shows who's currently viewing a thread.
It's in ACP->Settings->Options->Thread Display Options(showthread).
emath
05-15-2013, 08:07 PM
oh, i thought there is a variable for that.
i have made a refresh button for the thread information using ajax... so thats the replaced text when clicking on the button .
regarding the issue, it does happend also on firefox now for some reason, but i have no idea what is the problem .
why would $activeusers would be invalid for foreach ..
--------------- Added 1368652200 at 1368652200 ---------------
this is the code for $activeusers in showthread :
$activeusers = array();
if ($vbulletin->userinfo['userid']) // fakes the user being in this thread
{
$loggedin = array(
'userid' => $vbulletin->userinfo['userid'],
'username' => $vbulletin->userinfo['username'],
'invisible' => $vbulletin->userinfo['invisible'],
'invisiblemark' => $vbulletin->userinfo['invisiblemark'],
'inthread' => $threadinfo['threadid'],
'lastactivity' => TIMENOW,
'musername' => $vbulletin->userinfo['musername'],
);
$numberregistered = 1;
$numbervisible = 1;
fetch_online_status($loggedin);
$loggedin['comma'] = $vbphrase['comma_space'];
$activeusers[$numberregistered] = $loggedin;
$doneuser["{$vbulletin->userinfo['userid']}"] = 1;
nhawk
05-15-2013, 08:17 PM
I've never done something like this with ajax, but if I'm not mistaken you need to rebuild the activeusers with a database query in your ajax code and save it to the ajax xml.
The way it is now, you don't have $activeusers in your ajax code. That's why the error is popping up.
Perhaps someone with more ajax experience than me will chime in on this.
emath
05-15-2013, 08:18 PM
you can see it on action on this page : http://www.emath.co.il/forums/%D7%97%D7%98%D7%99%D7%91%D7%AA-%D7%94%D7%91%D7%99%D7%A0%D7%99%D7%99%D7%9D/68746.htm
you need to click the button on the left ( see pic )
EDIT : IT IS WORKING FOR CHROME and WORKED for firefox... probably its something with the cookies the reason it worked with ff and not its not. though it is working, no need to rebuild the $activeusers ...
emath
05-15-2013, 08:22 PM
IT seems that if im not logged in, its working otherwise, gives the invalid error.
--------------- Added 1368653172 at 1368653172 ---------------
*sigh*
i guess the error is because the $activeusers is empty (when no user is logged in..)
thanks for the help..
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.