View Full Version : Query results above header...
Doc203
08-29-2004, 10:35 PM
I have a php script with a query on it and if I call the page up with a "basic page" template the results are always at the top of the page, above the header etc and I want the results to show in the body of the page. Any Ideas?
Doc203
08-30-2004, 01:43 AM
Here is a link: My Test Page (http://www.searchforautoparts.net/forum/test.php)
Here is the php script:
<?PHP
$templatesused = "postdate";
require("./global.php");
$start_date = "2004-07-01 00:00:00";
$end_date = "2004-07-31 00:00:00";
$stmt = $DB_site->query("SELECT COUNT(post.postid) AS count, user.username
FROM post
LEFT JOIN user ON (user.userid = post.userid)
AND (UNIX_TIMESTAMP('$start_date')) <= post.dateline
AND post.dateline <= (UNIX_TIMESTAMP('$end_date'))
GROUP BY user.userid ORDER BY count DESC, username");
echo "<table border=1 cellspacing=0>";
$result = ($stmt) or die (mysql_error()."<br />Couldn't execute query: $stmt");
while($row = mysql_fetch_row($result))
{
echo "<tr>";
for($i = 0; $i < mysql_num_fields($result); $i++)
{
echo "<td>" . $row[$i] . "</td>";
}
echo "</tr>";
}
echo "</table>";
eval('print_output("' . fetch_template('TEST') . '");');
eval('$navbar = "' . fetch_template('navbar') . '";');
?>
and the template:
$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">Text</td>
</tr>
</table>
$footer
</body>
</html>
Can I just assign a variable in Includes_start and call it in the template?
you can never output anything via an echo or print command. replace echo with a variable, ($myvar = "<tr>"; for example) and then place that variable in your test template.
Doc203
08-30-2004, 10:47 AM
So can I assign a variable to this part of the scritp and then call that variable in a template?
{
echo "<tr>";
for($i = 0; $i < mysql_num_fields($result); $i++)
{
echo "<td>" . $row[$i] . "</td>";
}
echo "</tr>";
}
echo "</table>";
I tried adding this to my phpinclude_start template, so I could call the variable in my templates and it worked, but I would get random database errors I am assuming from too many mysql connections being as it was running the query everytime that ANY page was loaded.
ob_start();
include("postcountdate.php");
$postcount = ob_get_contents();
ob_end_clean();
I guess my problem is defining a php variable so it can be called in a template. Thanks for the help.
You don't need to do that. Any variable in the script can be used in a template.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.