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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.