Jump to content

[SOLVED] visa versa


nelquintin

Recommended Posts

i use this line to match customer with product

$query = "SELECT * FROM product WHERE price BETWEEN '".$_POST['minprice']."' AND '".$_POST['maxprice']."'";
$result = mysql_query($query); 

how can i match the product with customer? Bearing in mind the customer has a min range and a max range and product a set price.

Link to comment
https://forums.phpfreaks.com/topic/118065-solved-visa-versa/
Share on other sites

Try nesting. 

 

SELECT * FROM customers WHERE (max_price < '$x' AND customer_id = '1') OR (min_price > '$x' AND customer_id = '2')

 

Not the code to use but Im sure you can work something out so you dont select ALL your customers and hit your range correctly for each customers specified ranges...

Link to comment
https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-608467
Share on other sites

// some code $link= 
$query = "SELECT * FROM `customers` WHERE `price_min` <= '" . $_POST['price'] . "' 
  AND `price_max` >= '" . $_POST['price'] . "'"; 
  $result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "\t<tr>\n";
   foreach ($line as $col_value) {
       echo "\t\t<td>$col_value</td>\n";
   }
   echo "\t</tr>\n";
}
echo "</table>\n";
mysql_free_result($result);
mysql_close($link);
?>

sql dump:

/*!40000 ALTER TABLE `customers` DISABLE KEYS */;

INSERT INTO `contacts` (`username`,`price_max`,`price_min`) VALUES

('quintin','100','10');

/*!40000 ALTER TABLE `customers` ENABLE KEYS */;

 

this returns nothing why??

Link to comment
https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-609794
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.