Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-11-2010, 01:47 AM
DustyJoe DustyJoe is offline
 
Join Date: Dec 2007
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Newbie SQL + template question please.

I need help please.

I'm very new to the vbulletin code as well as sql. I'm toying around with my software and I'm working on a small "garage" if you will, I guess you could say I'm using this as a learning process..

I have things set up already to work without going thru the vbulletin templates and I'm trying to set that up now.

I'm needing to read all the data from the table and pass all the data to the templates but I'm lost on how to do this, all I can manage to do is send one line over instead of everything.

bamfg.php
PHP Code:
<?php

error_reporting
(E_ALL & ~E_NOTICE);

define('THIS_SCRIPT''bamfg');
define('CSRF_PROTECTION'true);  

$phrasegroups = array();
$specialtemplates = array();
$globaltemplates = array('bamfg_main');
$actiontemplates = array();

require_once(
'./global.php');

$navbits construct_navbits(array('' => 'Test Page'));
$navbar render_navbar_template($navbits);




$query "SELECT * FROM BAMFG_vehicle"
$result mysql_query($query) or die(mysql_error());

while(
$row mysql_fetch_array($result))
{
$yearz $row['year'];
$makez $row['make_model'];
}



$templater vB_Template::create('bamfg_main');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('pagetitle'$pagetitle);

$templater->register('year'$yearz);
$templater->register('make_model'$makez);

print_output($templater->render());
?>
Of course, with the code above it will only send the data from the very last query over to the template.

If I were to move the parts of the code up inside the while statement then it would send the very first query of the table over to the template.

This is where I'm lost =/

Here is my template code.
bamfg_main
PHP Code:
{vb:stylevar htmldoctype}
<
html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <
head>
    <
title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {
vb:raw headinclude}
    {
vb:raw headinclude_bottom}
  </
head>
  <
body>
    
    {
vb:raw header}
    
    {
vb:raw navbar}
    
    <
div id="pagetitle">
      <
h1>{vb:raw pagetitle}</h1>
    </
div>


{
vb:raw year}
{
vb:raw make_model}
    
    <
h2 class="blockhead">Title</h2>
    <
div class="blockbody">
      <
div class="blockrow">
        
Text
      
</div>
    </
div>
    
    {
vb:raw footer}
  </
body>
</
html

Thanks alot guys, I'm going to be searching the forums some more as well.
Reply With Quote
  #2  
Old 10-12-2010, 12:50 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You really should have a template just for the year/model, but the down and dirty method would be something like:
PHP Code:
while($row mysql_fetch_array($result)) 

$yearz $row['year']; 
$makez $row['make_model']; 
$myoutput .= "Year: " .$yearz" Make: " .$makez"<br />";




$templater vB_Template::create('bamfg_main'); 
$templater->register_page_templates(); 
$templater->register('navbar'$navbar); 
$templater->register('pagetitle'$pagetitle); 

$templater->register('$myoutput'$myoutput);
 
print_output($templater->render()); 
Then put {vb:raw myoutput} into your template.
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 12: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.03130 seconds
  • Memory Usage 2,193KB
  • Queries Executed 11 (?)
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
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)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_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