So here is the problem, I have an index.php
(with all the php code) and I have an index.tpl
file with all the html stuff. But now because I am using ajax I have another php file that should output some data (data.php). The problem is that I don't know how to select the template in the data.php file, all I know is on the index.php
I have a function that displays the tpl ($Smarty->display($filename);
) but I don't want to display the template (again) in the data.php
file I just want to assign some variables that need to show on index.tpl
EDIT:
Ok this is going to be long: First I need to explain what do I want to accomplish. I have the index.php and the data.php. The index.php:
<?php
include("../include/config.php");
include("../include/functions/import.php");
$thebaseurl = $config['baseurl'];
$query ="SELECT name FROM contacts";
$results = $conn->execute($query);
$select-names = $results->getrows();
STemplate::assign('select-names',$select-names);
$templateselect = "index.tpl";
STemplate::display($templateselect);
?>
The index.tpl is a little long so I will post the important part:
xmlhttp.open("get","data.php?q="+str,true);
This is AJAX code, this code sends +str value in GET method to the data.php file that then uses the value and pulls some data from the database.
data.php:
$q=$_GET["q"];
$sql="SELECT * FROM contacts WHERE name = '$q'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$name = $row['name'];
}
STemplate::assign('name',$name);
$templateselect = "index.tpl";
STemplate::display($templateselect); //the second display
?>
I use that class here STemplate for the smarty functions, but you get what is the code.
I hope you understand what is the problem now. How can I assign variables to a template without displaying the template file again. This way the $name variable is accessible in the index.tpl (the name is shown from the db) but the whole content is shown again because of the dispaly function in the data.php.