I would like to send a php variable to a class that runs a mysql query. It is a typical search via html form. I have to use Smarty.
How can I pass the variable "$minta" to the sql query and how to get the result array back to the php to display?
The Smarty tpl file is OK (lista_keres.tpl with the ingatlank variable).
Thank you in advance.
Tuwanbi
The php:
if (isset($_POST['keresoszo'])){
include_once "classes/ingatlan.class.php";
include_once "classes/main.class.php";
include_once "classes/felhasznalo.class.php";
$ingatlan = new Ingatlan();
$felhasznalo = new Felhasznalo();
$minta = $_POST['keresoszo'];
$kereses = new Main();
$kereses->getKeresIngatlan($minta);
$smarty->assign("kapcsolattartok", $ingatlan->getKapcsolattartok());
$smarty->assign("ingatlank", $main->getKeresIngatlan());
$smarty->assign("include_file", lista_keres);
echo $minta;
}
The class:
<?php
class Main{
private $keresoszo;
...
public function getKeresIngatlan($minta){
$this->keresoszo=$minta;
$ret = array();
$sql="SELECT id FROM table WHERE id LIKE '% ".$keresoszo." %'";
$ret = $this->db->GetArray($sql);
return $ret;
}
}
?>
Declaring private $keresoszo;
it becomes the class object and can be accessible by $this->keresoszo
in you sql query you have assigned the value to this object but haven't used it
<?php
class Main{
private $keresoszo;
...
public function getKeresIngatlan($minta){
$this->keresoszo=$minta;
$ret = array();
$sql="SELECT id FROM table WHERE id LIKE '% ".$this->keresoszo." %'";
$ret = $this->db->GetArray($sql);
return $ret;
}
}
?>
Here is what how you can get back the results
$kereses = new Main();
$results_set=$kereses->getKeresIngatlan($minta);
var_dump($results_set);// for testing only
$smarty->assign("my_results_set", $results_set);