vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Error .. 1054 MYSQL .. Where Clause seems correct .. ideas? (https://vborg.vbsupport.ru/showthread.php?t=119700)

LBSources 06-26-2006 06:45 PM

Error .. 1054 MYSQL .. Where Clause seems correct .. ideas?
 
This is a simple statement to draw some info on a home page regarding user stats .. right now the error i get is
Quote:

Invalid SQL:
SELECT userid, username FROM myprefix_user WHERE myprefix_userid=2;

MySQL Error : Unknown column 'myprefix_userid' in 'where clause'
Error Number : 1054

I changed the prefix in this example, but the correct prefix is in the error. What exactly is it complaining about?

Code:

// forum stats start 
$numbersmembers = $db->query_first("SELECT COUNT(*) AS users,MAX(userid) AS max FROM " . TABLE_PREFIX . "user"); 
$numbermembers = number_format($numbersmembers['users']); 
$counter = $db->query_first("SELECT COUNT(postid) AS posts, COUNT(threadid) AS threads FROM " . TABLE_PREFIX . "post");
$totalposts=number_format($counter['posts']); 
$countthreads = $db->query_first("SELECT COUNT(*) AS threads FROM " . TABLE_PREFIX . "thread");
$totalthreads=number_format($countthreads['threads']); 
// forum stats end 

// total online start 
$datecut = TIMENOW - $vbulletin->options['cookietimeout']; 
$headerguests=$db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "session WHERE userid=0 AND lastactivity>$datecut"); 
$headerusers=$db->query_first("SELECT COUNT(DISTINCT(userid)) AS count FROM " . TABLE_PREFIX . "session WHERE " . TABLE_PREFIX . "session.userid>0 AND " . TABLE_PREFIX . "session.lastactivity>$datecut"); 
$headerguests=$headerguests[count]; 
$headerusers=$headerusers[count]; 
$totalonline=$headerguests+$headerusers; 
// total online end

// get newest member name and userid start 
$getnewestmember=$db->query_first("SELECT userid, username FROM " . TABLE_PREFIX . "user WHERE " . TABLE_PREFIX . "userid=$numbersmembers[max]"); 
$newusername = $getnewestmember['username']; 
$newuserid = $getnewestmember['userid']; 
// get newest member name and userid end


LBSources 06-27-2006 10:56 PM

bump ..

Adrian Schneider 06-27-2006 11:45 PM

[sql]SELECT userid, username FROM myprefix_user WHERE userid=2;[/sql]

LBSources 06-27-2006 11:56 PM

ive seen the page before i was more hoping for somone to point out the error if it jumped out at them ..

I see the section you are pointing out, but how can i also set that syntax in this code.

cause it seems the problem is at this section

Code:

$headerguests=$db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "session WHERE userid=0 AND lastactivity>$datecut");

Paul M 06-28-2006 03:16 AM

This is the same error as this thread ;

https://vborg.vbsupport.ru/showthread.php?t=119719

The broken line is this one ;

PHP Code:

$getnewestmember=$db->query_first("SELECT userid, username FROM " TABLE_PREFIX "user WHERE " TABLE_PREFIX "userid=$numbersmembers[max]"); 

The table name is missing from the WHERE section after the table prefix.

i.e. TABLE_PREFIX . "userid should be TABLE_PREFIX . "user.userid

However, table prefix should not be used in WHERE clauses anyway, instead you should us an AS after the initial table selection, like this ;

PHP Code:

$getnewestmember=$db->query_first("SELECT userid, username FROM " TABLE_PREFIX "user AS user WHERE user.userid=$numbersmembers[max]"); 

Finally, since only one table is actually used in this select, the table references can be dropped completely as no ambiguity is possible.

PHP Code:

$getnewestmember=$db->query_first("SELECT userid, username FROM " TABLE_PREFIX "user WHERE userid=$numbersmembers[max]"); 


LBSources 06-28-2006 03:25 AM

Paul, thanks this did help me also :)

VBUsers 06-28-2006 03:31 AM

Thank you for the help much appreciated.


All times are GMT. The time now is 01:28 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.01005 seconds
  • Memory Usage 1,735KB
  • 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
  • (2)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete