Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying columns data in PHP search
    text
    copied!<p>I have MySQL table called products and in this table I have data: </p> <pre><code>id | category | product1 | price1 | discount1 | product2 | price2 | discount2 | product3 | price3 |discount3 | ---------------------------------------------------------------------------------------------------------- | 1 | Meat | Pork 1kg | 3.99 | -30% | Lamb 1kg | 5.94 | -25% | Ham 200g | 1.99 | -10% | | 2 | Fruit | Apple 1kg| 1.25 | -32% | Banana 1 kg | 0.99 | -15% | Melon 1 kg | 0.79 | -12% | </code></pre> <p>PHP search script I have looks like this:</p> <pre><code>//-query the database table $sql="SELECT id, category, product1, price1, discount1, product2, price2, discount2, product3, price3, discount3 FROM products WHERE product1 LIKE '%" . $name . "%' OR price1 LIKE '%" . $name ."%' OR discount1 LIKE '%" . $name ."%' OR product2 LIKE '%" . $name ."%' OR price2 LIKE '%" . $name ."%' OR discount2 LIKE '%" . $name ."%' OR product3 LIKE '%" . $name ."%' OR price3 LIKE '%" . $name ."%' OR discount3 LIKE '%" . $name ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $id=$row['id']; $category =$row['category']; $product1=$row['product1']; $price1=$row['price1']; $discount1=$row['discount1']; $product2=$row['product2']; $price2=$row['price2']; $discount2=$row['discount2']; $product3=$row['product3']; $price3=$row['price3']; $discount3=$row['discount3']; //-display the result of the array echo "&lt;ul&gt;\n"; echo "&lt;li&gt;" . $id . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $category . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $product1 . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $price1 . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $discount1 . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $product2 . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $price2 . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $discount2 . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $product3 . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $price3 . "&lt;/li&gt;\n"; echo "&lt;li&gt;" . $discount3 . "&lt;/li&gt;\n"; echo "&lt;/ul&gt;"; } </code></pre> <p>The problem is that when I search for let's say Apple, Banana and Melon are also displayed. </p> <p>How can I make it to show only Apple and it's price and discount when searching with keyword apple. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload