View Full Version : Running a Query in a template
VBCoder
07-12-2005, 09:42 PM
I'd like to have the value of a query (SELECT...) or a function from within a template. Where's the best place for me to put it?
Should I put it in the .php file that calls the template? (I've seen some people put in their global include, but that is very wasteful of resources...)
Dream
07-12-2005, 09:49 PM
"hook postbit_create"
$blah = $db->query_read("SELECT * FROM ")
"filter results"
$blah = '<a href="disney.com">' . $filtered . '</a>';
in the postbit template put $blah where you want the text to appear
put the query in a hook and make the variable there... not sure this was the question
VBCoder
07-12-2005, 10:02 PM
"hook postbit_create"
$blah = $db->query_read("SELECT * FROM ")
"filter results"
$blah = '<a href="disney.com">' . $filtered . '</a>';
in the postbit template put $blah where you want the text to appear
put the query in a hook and make the variable there... not sure this was the question
Thanks Dream, yes, this is my question.
What do you mean by "filter results"?
Dream
07-12-2005, 10:12 PM
well
$result = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "user");
$a = '';
while( $user = $db->fetch_array( $result ) ) {
$a .= "($user[username], userid $user[userid])<br />";
}
then put $a in a template to show the list of users... just an example, hope it helps
if you want just the first row, you could use
$user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user");
$a .= "($user[username], userid $user[userid])<br />";
VBCoder
07-13-2005, 01:30 AM
Thanks, got it.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.