vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   What am I doing wrong here? (https://vborg.vbsupport.ru/showthread.php?t=48891)

N9ne 02-13-2003 07:28 PM

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?

Xenon 02-13-2003 07:35 PM

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 :)

N9ne 02-13-2003 07:40 PM

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! :)

Xenon 02-13-2003 07:53 PM

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

N9ne 02-13-2003 07:58 PM

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!

Xenon 02-13-2003 08:03 PM

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!");
    } 


N9ne 02-13-2003 08:17 PM

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...

Xenon 02-13-2003 08:18 PM

total is just a counter, it will save the ammount of admins online :)

N9ne 02-13-2003 08:25 PM

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?

Xenon 02-13-2003 09:05 PM

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");
    } 



All times are GMT. The time now is 07:51 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02553 seconds
  • Memory Usage 1,750KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete