vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How do I display a result of a query? (https://vborg.vbsupport.ru/showthread.php?t=109145)

DrewM 02-28-2006 07:13 PM

How do I display a result of a query?
 
Well I'm trying to show the Results from a data base query in a templeat can any one tell me how to do this?

tehste 02-28-2006 07:20 PM

Quote:

Originally Posted by Larrysw
Well I'm trying to show the Results from a data base query in a templeat can any one tell me how to do this?

well you need to put the results into an array. Unless it's a query_first as there is only one result so it will be in an array already.

Then just use $foo[foo] in the templates.

DrewM 02-28-2006 07:41 PM

I know how to do arrays but can you show me a exaple code my tables fields are:
id
name
url
description

Nullifi3d 02-28-2006 09:29 PM

$variable = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "tablename WHERE id = id");
$variable['id']
$variable['name']
$variable['url']
$variable['description']

DrewM 02-28-2006 09:36 PM

thank you

That code cases errors

anyone?

DrewM 03-01-2006 10:04 PM

help!

Nullifi3d 03-01-2006 10:25 PM

what error?????

DrewM 03-01-2006 10:34 PM

I get:
Parse error: parse error, unexpected T_VARIABLE in /home/rdsx667/public_html/tutorials/test.php on line 55

EDIT: before this code there was no error ( This isn't suppose to sound rude)

Nullifi3d 03-01-2006 10:46 PM

please disply your code to me. lines 50-60.

DrewM 03-01-2006 10:47 PM

heres the code:
$variable = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "tablename WHERE 1 = Links");
$variable['id']
$variable['name']
$variable['url']
$variable['description']
eval('print_output("' . fetch_template('site_test') . '");');

Nullifi3d 03-01-2006 11:06 PM

lol, you have to put:
$variable['id'], $variable['name'], $variable['url'], $variable['description'] in your template (site_test). $variable['id'] would display the mysql field id as do the other variables have the sam operation.

and with the query you need to change tablename to your mysql table name. ANd change 1 to a valid mysql field (i think this would be id, name, description, or url).

DrewM 03-02-2006 07:12 PM

I get this error when I save the templeat:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/rdsx667/public_html/forum/includes/adminfunctions_template.php(3537) : eval()'d code on line 18

Nullifi3d 03-02-2006 08:10 PM

Just to let you know. it's extremly hard for peole to help you if you don't post the code you're using when you list errors. When asking for help try to list the error and your code.

Remove the ' from the variables when putting them in vbulletin templates.

DrewM 03-02-2006 08:55 PM

sorry about this I'll try removing ' from it though.
It works with this thank you for the help.

on more question and I'm done how do I make the code repeat for the resaults?

Nullifi3d 03-03-2006 01:46 AM

you mean print the results for each row in the table?

DrewM 03-03-2006 09:45 AM

yes, help much apprictated

Nullifi3d 03-07-2006 10:26 PM

PHP Code:

$rows $db->query_read("SELECT * FROM " TABLE_PREFIX "tablenamehere");
while (
$row $db->fetch_array($rows)) {
    eval(
'$rowbits .= "' fetch_template('templatenamehere') . '";');


Replace 'tablenamehere' with the name of the table which has the rows you want to print out. Replace 'templatenamehere' with the name of the template you want printed for every row in that table. Obviously you have to create a new template (templatenamehere). This template will be printed to the browser (eval'd) over and over again for each row in the table (tablenamehere). In the template you put your html and variables you want displayed for each row.

DrewM 03-07-2006 10:29 PM

thanks for the help it is much apprcated.

Nullifi3d 03-07-2006 10:35 PM

No prob, glad to help.


All times are GMT. The time now is 02:20 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.01283 seconds
  • Memory Usage 1,748KB
  • 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_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (19)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