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 05-16-2006, 09:53 AM
aussiev8 aussiev8 is offline
 
Join Date: Aug 2004
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default help with query

can anyone help?

PHP Code:
$sql $DB_site->query("SELECT COUNT( * ) AS texts FROM encyclopedia_text WHERE title LIKE '$ltr%'"); 
i've got the error,
Code:
Fatal error: Call to a member function on a non-object in /home/aussie7/public_html/encyclopedia.php on line 58
Reply With Quote
  #2  
Old 05-16-2006, 10:06 AM
The Geek's Avatar
The Geek The Geek is offline
 
Join Date: Sep 2003
Location: Behind you
Posts: 2,779
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$DB_site was for 3.0x series use $db for 3.5.x

Another reason is that you may need to put:
global $DB_site;
or
global $db;

above the code to make it accessible if it is in a function.

HTH's
Reply With Quote
  #3  
Old 05-16-2006, 10:17 AM
aussiev8 aussiev8 is offline
 
Join Date: Aug 2004
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks, but neither worked, even with the globals.
Reply With Quote
  #4  
Old 05-16-2006, 10:25 AM
Hellcat Hellcat is offline
 
Join Date: May 2003
Location: Germany
Posts: 560
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

vB 3.0 or 3.5?

For 3.5 you could also try this:
PHP Code:
global $vbulletin;
$r $vbulletin->db->query_write"...." ); 
Reply With Quote
  #5  
Old 05-16-2006, 10:31 AM
aussiev8 aussiev8 is offline
 
Join Date: Aug 2004
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nah it didn't work either.
and version 3.5

below is a snippet of code, its going to be an encyclopedia that i'm going to share here. It was working on 3.0 and i'm rewriting it for 3.5 (now i have some spare time) and all the other scripts in my vb dir have $DB_site.
PHP Code:
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS'1);

define('THIS_SCRIPT''encyclopedia');



// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
    
'user',
    
'cpglobal'
);

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
    
'ENCYCLOPEDIA',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
'./includes/functions_bbcodeparse.php');
require_once(
'./includes/functions_user.php');
require_once(
'./includes/adminfunctions.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################


    
if (empty($_REQUEST['do']))
    {
        
$_REQUEST['do'] = 'list';
    }
    
    global 
$vbulletin;
    
$r $vbulletin->db->query_write"select * from encyclopedia");

    
$alpha = array ("A","B","C","D","E","F","G","H","I","J","K","L","M",
                        
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
    
$num count($alpha);
     
    for(
$x 0$x $num$x++) {
        
$ltr $alpha[$x];
        
$sql $vbulletin->$db->query("SELECT COUNT( * ) AS texts FROM encyclopedia_text WHERE title LIKE '$ltr%'");
        
$numrows $vbulletin->$db->fetch_Array($sql); 
Reply With Quote
  #6  
Old 05-16-2006, 11:04 AM
The Geek's Avatar
The Geek The Geek is offline
 
Join Date: Sep 2003
Location: Behind you
Posts: 2,779
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

change:
PHP Code:
    global $vbulletin;
    
$r $vbulletin->db->query_write"select * from encyclopedia"); 
to

PHP Code:
$r $db->query_read("SELECT * FROM " TABLE_PREFIX "encyclopedia"); 
Futhermore, your query for the letters is incorrect AND will have A LOT of overhead (at least 26 additional gob searches).
Reply With Quote
  #7  
Old 05-16-2006, 11:35 AM
aussiev8 aussiev8 is offline
 
Join Date: Aug 2004
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$db->query_read did the trick... thanks..

i can't log into the API, it keeps throwing errors, then takes ages to load... bit of a pitty. but thanks to everyone who helped
Reply With Quote
  #8  
Old 05-16-2006, 12:00 PM
The Geek's Avatar
The Geek The Geek is offline
 
Join Date: Sep 2003
Location: Behind you
Posts: 2,779
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

no problemo.

I would think about something like a table with the following fields:
id, symbol, total

then when someone edits or creates a new entry, take the first letter of the entry and update the above table accordingly.
Then you can just dosomething like:
PHP Code:
$results $db->query_read("SELECT symbol, total FROM " TABLE_PREFIX "encyclopedia_dir ORDER BY Symbol ASC");

$my_nav = array();

while (
$result $db->fetach_array($results))
{
$my_nav[$result['symbol']] = $result['total'];

Thats just one of 1,000's ways to do what you're after without the MASSIVE overhead of doing an aggregate 26 times on a table via a gob search.

The other way is to then cache the above results in the datastore or in a file. Then you can avoid the query every page refresh (however, a query like that would be VERY minor).

Good luck.
Reply With Quote
  #9  
Old 05-16-2006, 12:35 PM
hambil's Avatar
hambil hambil is offline
 
Join Date: Jun 2004
Location: Seattle
Posts: 1,719
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by aussiev8
nah it didn't work either.
and version 3.5

below is a snippet of code, its going to be an encyclopedia that i'm going to share here. It was working on 3.0 and i'm rewriting it for 3.5 (now i have some spare time) and all the other scripts in my vb dir have $DB_site.
PHP Code:
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS'1);

define('THIS_SCRIPT''encyclopedia');



// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
    
'user',
    
'cpglobal'
);

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
    
'ENCYCLOPEDIA',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
'./includes/functions_bbcodeparse.php');
require_once(
'./includes/functions_user.php');
require_once(
'./includes/adminfunctions.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################


    
if (empty($_REQUEST['do']))
    {
        
$_REQUEST['do'] = 'list';
    }
    
    global 
$vbulletin;
    
$r $vbulletin->db->query_write"select * from encyclopedia");

    
$alpha = array ("A","B","C","D","E","F","G","H","I","J","K","L","M",
                        
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
    
$num count($alpha);
     
    for(
$x 0$x $num$x++) {
        
$ltr $alpha[$x];
        
$sql $vbulletin->$db->query("SELECT COUNT( * ) AS texts FROM encyclopedia_text WHERE title LIKE '$ltr%'");
        
$numrows $vbulletin->$db->fetch_Array($sql); 
Also, you don't want the second $:
wrong: $vbulletin->$db
right: $vbulletin->db
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 07:44 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.04239 seconds
  • Memory Usage 2,302KB
  • 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
  • (7)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete