php - i can not figure out how to implement search engine into sql syntax

691
foreach($dbh->query  ('SELECT a.tovar = '$users_input',
( select sum(b.kusy) from jednotypredaj as b where b.tovar=a.tovar and b.co="prijem" ) as prijem_ks,
( select sum(c.kusy) from jednotypredaj as c where c.tovar=a.tovar and c.co="predaj" ) as predaj_ks
FROM jednotypredaj  as a GROUP BY a.tovar ORDER by predaj_ks DESC') as $row)

I can not find reason why'SELECT a.tovar = '$users_input', does not work for my search engine.

118

Answer

Solution:

Thanks you But do not know how to really use it my whole code looks like this`

$hostname="localhost";  
$username="kintrogorgo";  
$password="password";  

$db = "jednoty";  
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);  
foreach($dbh->query  ('SELECT a.tovar ,
( select sum(b.kusy) from jednotypredaj as b where b.tovar=a.tovar and b.co="prijem" ) as prijem_ks,
( select sum(c.kusy) from jednotypredaj as c where c.tovar=a.tovar and c.co="predaj" ) as predaj_ks
FROM jednotypredaj  as a GROUP BY a.tovar ORDER by predaj_ks DESC') as $row)
 {  

echo "<tr>"; 
echo "<td>" . $row['tovar'] . "</td>";  
echo "<td>" . $row['prijem_ks']. "</td>";  //Tu by mali bit predane kusy
echo "<td>" . $row['predaj_ks'] . "</td>";  

echo "<td>" . ($row['predaj_ks']-$row['prijem_ks'] . "</td>");
echo '<td><a href="3edit.php?tovar=' . $row['tovar'] . '">ZobraziƄ</a></td>';
echo "</tr>";   
}  


?>  `

And i would like to add here search engine to be able search in any row. thank s you

People are also looking for solutions to the problem: php - How to pass chosen value from drop down list to the database table

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.