kiran patel kiran patel - 2 months ago 8
MySQL Question

How should I compare two different product price in php script?

is an array with unique product ids passed on from previous in the following page I want to look in the database using that
, get information and compare the prices of the product corresponding to each
from an

So far I can display the relevant product information using
) in the following format

productid | product name| price |

20______|__iphone5__|_529 |

i am using the code :

foreach($compare as $value) {

$query = mysql_query("SELECT * FROM `product_info` WHERE `productid`=".$value."");
echo "<table border='1' bordercolor='#000066'>
<th>product name</th><br />

while ($query_row=mysql_fetch_assoc($query)) {
echo "<tr bgcolor='#F5FFFF'>";
echo "<td>". $query_row['productid']. "</td>";
echo "<td>". $query_row['title']. "</td>";
echo "<td>". $query_row['price']."</td>";
echo "</tr>";
echo "</table>";

Please give me any suggestion how to compare the price of each product and say like "productA is £_ cheaper than productB" something similar to that would also work.please help.


Move the prices to a new array say product_prices[].

$product_prices['$productID'] = $query_row['price'];

You can then sort this array by increasing/decreasing order of prices and then subtract prices between individual keys.

How you work with the product_prices array is totally left to you and the use case that you have.