vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   accessing query results on custom page (https://vborg.vbsupport.ru/showthread.php?t=80642)

Oreamnos 04-27-2005 06:11 AM

accessing query results on custom page
 
i am attempting to build my first vb powered page via this tutorial: https://vborg.vbsupport.ru/showthread.php?t=62164

everything from that tut is working fine but i am running a query and cant seem to access the results in a template.

basically this is what i have:
PHP Code:

<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS'1);
define('THIS_SCRIPT''contest_stats'); // change this depending on your filename

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

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

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

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

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
$startdate 1112313600;
$enddate 1114819200;
$get_thread_stats "<a href=\"contest_stats.php?do=stats&type=threads\">Get Thread Starter Stats</a>";

if (
$_REQUEST['do'] == "stats") {
    
// user has requested stats so get them
    // chould we get most threads started, most posts or most referrals?
    
if ($_REQUEST['type'] == "threads") {
    
        
$most_threads "";
        
$threads $DB_site->query_first("
            SELECT postusername
            FROM " 
TABLE_PREFIX "thread");
            
        while (
$row $DB_site->fetch_array($threads)) {
            
$most_threads .= $row['postusername'] . "<br />";
        }
        
    
    } elseif (
$_REQUEST['type'] == "posts") {
    
    } elseif (
$_REQUEST['type'] == "referrals") {
    
    }
    

}



$navbits = array();
$navbits[$parent] = 'Contest Statistics';
$navbits construct_navbits($navbits);
eval(
'$navbar = "' fetch_template('navbar') . '";');
eval(
'print_output("' fetch_template('contest_stats') . '");');

?>

template
HTML Code:

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
        <td class="tcat">Title</td>
</tr>
<tr>
        <td class="alt1">

$get_thread_stats
<br />
$most_threads
<br />
$row[postusername]

</td>
</tr>
</table>

$footer
</body>
</html>

i have $most_threads and $row[postusername] but still no luck.

any ideas how i can access my query results?

thanks
eric

Marco van Herwaarden 04-27-2005 06:49 AM

If you are using a query_first (as opposed to simple "query") you don't need to fetch the rows afterwards, this is automatically done.

So just remove the while block and replace with:
PHP Code:

$most_threads $threads['postusername']; 

PS query_first will only retrieve 1 row.

Oreamnos 04-27-2005 08:18 AM

ok, thanks for heads up on the query_first thing. i thought that was a little weird.

i still couldnt get it to work without a while loop.

heres what worked for me:
PHP Code:

$threads $DB_site->query("SELECT * FROM " TABLE_PREFIX "thread");
        
        while (
$thread $DB_site->fetch_array($threads)) {
            
$most_threads .= $thread['postusername'] . "<br />";
        } 

thanks again

eric

Marco van Herwaarden 04-27-2005 09:42 AM

Yes if you use "query" then you will need a loop to read the rows.

Oreamnos 04-27-2005 09:43 AM

cool, thanks for your help. im rolling now :D


All times are GMT. The time now is 06:15 PM.

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.03960 seconds
  • Memory Usage 1,754KB
  • 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_html_printable
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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