Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-13-2003, 07:28 PM
N9ne N9ne is offline
 
Join Date: Feb 2002
Posts: 1,495
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default What am I doing wrong here?

PHP Code:
<?php
require('forum/admin/config.php');
$db mysql_connect($servername,$dbusername,$dbpassword) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

unset(
$servername,$dbusername,$dbpassword,$dbname);

$adminonline mysql_query("SELECT userid FROM session");

    if (
$adminonline['userid'] == 1) {
        echo(
"admin is online");
    } else {
        echo(
"admin is not online!");
    }

?>
I'm trying to see if userid 1 is online on the forum, and if he is, it will say admin is online. However, it just shows admin is not online!

Why is it doing this? Is there something i've missed out here?
Reply With Quote
  #2  
Old 02-13-2003, 07:35 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this line
Code:
$adminonline = mysql_query("SELECT userid FROM session");
results in a query result, not an array.
you have to use a fetch array command (as vb does nearly always).

also you should use WHERE userid=1 in the query
Reply With Quote
  #3  
Old 02-13-2003, 07:40 PM
N9ne N9ne is offline
 
Join Date: Feb 2002
Posts: 1,495
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well if I select userid, I can do the if conditions for multiple userids

I don't know how to do a fetch_array command, please could you show me how it would be done for me to achieve the correct results in my situation? Last time I needed help with hack (the intval function), you showed me how it was done, and then I managed to use it in another hack successfully!
Reply With Quote
  #4  
Old 02-13-2003, 07:53 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm, i don't know the mysql php commandos very good.., i always use the $DB_site var from vb

it would look something like that:

PHP Code:
$adminonline mysql_fetch_array(mysql_query("SELECT COUNT(userid) as total FROM session WHERE userid IN(1,4,5)"));

    if (
$adminonline['total'] > 1) {
        echo(
"admin is online");
    } else {
        echo(
"admin is not online!");
    } 
in the IN () you can speciafy the userids of all your admins
Reply With Quote
  #5  
Old 02-13-2003, 07:58 PM
N9ne N9ne is offline
 
Join Date: Feb 2002
Posts: 1,495
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I noticed that in index.php, in the code for online users, usergroupid is being called from the session table, I looked in the session table and there is no usergroupid field?! How can it be calling usergroupid if it isn't in the table?

Also, if I want to base it on usergroupid and not userid, how would I do that? I mean, it's definitely possible but the fact that there's no usergroupid field in the session table confuses me as I can't just call it because it doesn't exist!
Reply With Quote
  #6  
Old 02-13-2003, 08:03 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

in index.php there was used a joined query..

it's also possible but slows down the query a bit.

in that case it would look like that:
PHP Code:
$adminonline mysql_fetch_array(mysql_query("SELECT COUNT(userid) as total FROM session LEFT JOIN user USING(userid) WHERE user.usergroupid=6"));

    if (
$adminonline['total'] > 1) {
        echo(
"admin is online($adminonline[total])");
    } else {
        echo(
"admin is not online!");
    } 
Reply With Quote
  #7  
Old 02-13-2003, 08:17 PM
N9ne N9ne is offline
 
Join Date: Feb 2002
Posts: 1,495
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok so I'm almost there, I have one more question, what is the significance of 'total' in the query? What is it implying, what does it mean? This is a bit new to me as I'm used to just running a simple query, then using specific if conditions such as if ($adminonline['usergroupid'] == 6) but that's written into the query...
Reply With Quote
  #8  
Old 02-13-2003, 08:18 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

total is just a counter, it will save the ammount of admins online
Reply With Quote
  #9  
Old 02-13-2003, 08:25 PM
N9ne N9ne is offline
 
Join Date: Feb 2002
Posts: 1,495
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So I can go one step further and do this:

PHP Code:
$adminonline mysql_fetch_array(mysql_query("SELECT COUNT(userid) as total FROM session LEFT JOIN user USING(userid) WHERE user.usergroupid=6"));

$adminonline['total'] = $admintotal;

    if (
$adminonline['total'] > 1) {
        echo(
"There are $adminonline[total] admins online");
    } elseif (
$adminonline'total'] = 1) {
        echo(
"There is $adminonline[total] admin online");
    } else {
        echo(
"There are no admins online");
    } 
...and this would be perfectly valid?
Reply With Quote
  #10  
Old 02-13-2003, 09:05 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

two mistakes in it:

PHP Code:
$adminonline mysql_fetch_array(mysql_query("SELECT COUNT(userid) as total FROM session LEFT JOIN user USING(userid) WHERE user.usergroupid=6"));


    if (
$adminonline['total'] > 1) {
        echo(
"There are $adminonline[total] admins online");
    } elseif (
$adminonline['total'] == 1) {
        echo(
"There is $adminonline[total] admin online");
    } else {
        echo(
"There are no admins online");
    } 
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:05 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04294 seconds
  • Memory Usage 2,272KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete