nelquintin Posted August 4, 2008 Share Posted August 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/118065-solved-visa-versa/ Share on other sites More sharing options...
paulman888888 Posted August 4, 2008 Share Posted August 4, 2008 Do you mean like a shopping cart? I dont know what you mean but your code looks fine. Or do you want to echo it out in a table? Quote Link to comment https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-607342 Share on other sites More sharing options...
nelquintin Posted August 4, 2008 Author Share Posted August 4, 2008 that code is perfect when i am matching customer to the product. what i would like to do is match the product to the client. so for example if a book cost $20 i want to pull all the customer that have $20 in their price range. Quote Link to comment https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-607343 Share on other sites More sharing options...
wildteen88 Posted August 4, 2008 Share Posted August 4, 2008 You'd just change the table/field names accordingly, like so: $query = "SELECT * FROM customer_table WHERE customer_price_range_field BETWEEN '".$_POST['minprice']."' AND '".$_POST['maxprice']."'"; You'll need to change the bits in red. Quote Link to comment https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-607437 Share on other sites More sharing options...
nelquintin Posted August 5, 2008 Author Share Posted August 5, 2008 ive tried this $query = "SELECT * FROM customers WHERE '".$_POST['minprice']."' AND '".$_POST['maxprice']."' LIKE '".$_POST['price']."' "; nothing Quote Link to comment https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-608456 Share on other sites More sharing options...
JasonLewis Posted August 5, 2008 Share Posted August 5, 2008 Wouldn't you just select all people who have money that is greater then or equal to the price of the item? Quote Link to comment https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-608460 Share on other sites More sharing options...
BioBob Posted August 5, 2008 Share Posted August 5, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-608467 Share on other sites More sharing options...
nelquintin Posted August 5, 2008 Author Share Posted August 5, 2008 thanks ive tried $query = "SELECT * FROM customers WHERE price_min < '".$_POST['price']."' AND price_max > '".$_POST['price']."'"; this returns nothing Quote Link to comment https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-608493 Share on other sites More sharing options...
nelquintin Posted August 6, 2008 Author Share Posted August 6, 2008 // 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?? Quote Link to comment https://forums.phpfreaks.com/topic/118065-solved-visa-versa/#findComment-609794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.