show similar product/property with php and mysql

Asked

Viewed 210 times

0

I am developing a feature on my site to show similar properties by title and value 9r, but it did not work very well my idea:

<?php
//Armazeno o resultado do titulo da consulta anterior da tabela imoveis em um variável
$titulo_semelhante = $results['titulo'];
//Armazeno o resultado do valor do imóvel da consulta anterior em um variável
$valor_semelhante = $results['venda'];

//Realizo uma nova consulta, onde o titulo na tabela vw_exibir contenha a palavra da variavel $titulo_semelhante e contenha um valor menor ou igual a variavel $valor_semelhante
                    $q2 = $db->query("SELECT * from vw_exibir WHERE titulo LIKE '%$titulo_semelhante%' AND venda <= '".$valor_semelhante."' ");
                        foreach($q2 as $row){
                            print_r($row);
                        }
                    ?>

Always returns me that mistake:

<b>Fatal error</b>:  Problem preparing query (SELECT * from vw_exibir WHERE titulo LIKE &#39;%Apartamento em Balneário Camboriú%&#39; AND venda ) Você tem um erro de sintaxe no seu SQL próximo a '&#39;%Apartamento em Balneário Camboriú%&#39; AND venda' na linha 1 in <b>/home/himoveis/www/includes/MysqliDb.php</b> on line <b>447</b><br />

Can anyone tell me if I am developing this feature correctly, and why this error is returning?

OBS:

I use class - PHP-Mysqli-Database-Class When I do the same query with static values in phpmyadmin all this ok:

ex:SELECT * from vw_exibir WHERE titulo LIKE '%Apertamento%' AND venda <= 1500000

imóveis semelhantes

  • Try to use $db->prepare('Sua query'); and right after use $q2->execute()

  • @Rafaelacioly, I tried and had this return: <b>Fatal error</b>: Call to Undefined method Mysqlidb::prepare() in <b>/home/***/www/exclusive/tpl/imovel.php</b> on line <b>225</b><br />

  • go to your location -> PHP -> PHP Extension -> and select php_pdo_mysql

  • Already this in the hosting server, Pdo this active.

  • Put the code snippet that was wrong.

  • I would say that your problem is the encoding, probably your current encoding does not allow certain characters. You are extracting that value from an ajax request?

  • Igor, to do this it may be necessary to change your modeling. Can you ask the question the modeling of your tables that involve this search? On the basis of this information I will draw up a public utility response.

  • $db->query 'is a custom method? Because the html entities that appeared make me believe that Oce created a method of his own and used htmlspecialchars or htmlentities. I could give you more details of your codido?

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.