Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

show php mysql search result in tpl file of prestashop

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Italian
View previous topic :: View next topic  
Author Message
pixelbee
Smarty n00b


Joined: 03 Jul 2017
Posts: 1

PostPosted: Mon Jul 03, 2017 8:51 am    Post subject: show php mysql search result in tpl file of prestashop Reply with quote

I have this code, and i want to show search result in a tpl file of prestashop( that use smarty)
Can someone help me ? I have already created a custom tpl file for output.
Code:
<?
    $cn = mysql_connect("localhost", "mydatabase", "mypassword");
    @mysql_select_db("myuser", $cn);
    $testo = isset($_POST["testo"]) ? htmlspecialchars($_POST["testo"]) : '';
    $descrizione = isset($_POST["descrizione"]) ? htmlspecialchars($_POST["descrizione"]) : '';
?>
<html><head><title>Risultati della ricerca</title></head><body>
<p>
<b>Risultati della ricerca:</b>
<?
    if (!$testo)
    {
        echo "nessun risultato!";
    }
    else
    {
        echo $testo;
      echo $descrizione;
    }
?>
</p>
<?
    if (!$testo)
    {
?>
<p>Specificare un criterio di ricerca.</p>
<?
    }
    else
    {
        $arr_txt = explode(" ", $testo);
        $sql = "SELECT * FROM articoli WHERE ";
        for ($i=0; $i<count($arr_txt); $i++)
        {
            if ($i > 0)
            {
                $sql .= " AND ";
            }
            $sql .= "(titolo LIKE '%" . mysql_real_escape_string($arr_txt[$i]) . "%' OR descrizione LIKE '%" . mysql_real_escape_string($arr_txt[$i]) . "%')";
        }
        $sql .= " ORDER BY titolo ASC";
        $query = mysql_query($sql, $cn);
        $quanti = mysql_num_rows($query);
        if ($quanti == 0)
        {
?>
<p>Nessun risultato!</p>
<?
        }
        else
        {
            for($x=0; $x<$quanti; $x++)
            {
               
            $rs = mysql_fetch_row($query);
                $id = $rs[0];
                $titolo = $rs[1];
            $descrizione = $rs[2];
?>
<center>
<table cellpadding="1" cellspacing="0" border="1" width="70%" >
<tr>
<th>Sogno</th>
<th>Significato</th>
</tr>
<tr>
<td align="center"><?echo $titolo?></td>
<td align="center"><?echo $descrizione?></td>
</tr>
</table>
</center>
<p><?echo $id?>"><?echo $titolo?></p>
<p><?echo $descrizione?></p>
<?
            }
        }
    }
?>
</body></html>
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Italian All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP