View Full Version : How do I display a result of a query?
DrewM
02-28-2006, 07:13 PM
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
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
$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.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.