Jump to content

Halisco

Members
  • Posts

    20
  • Joined

  • Last visited

Everything posted by Halisco

  1. I have two seperate tables containing an customer_id that match when a customer purchases a particular type of fruit. I have a multi table 1 "customers": customer_id email phone 1 [email protected] 555-111-1111 2 [email protected] 555-222-2222 3 [email protected] 555-333-3333 customer_id type 1 macintosh 1 galla 2 galla 2 jonagold 3 jonagold Here is a shorter version of my item list i use for selecting the type of fruit i want to search for. <select name=fruit_type[] multiple> <option value="macintosh">macintosh</option> <option value="gala">a</option> <option value="jonagold">jonagold</option> </select> I then take that list and join it $search_fruit = filter_var_array($_POST['fruit_type'], FILTER_SANITIZE_SPECIAL_CHARS); $fruit_types = join("','", $search_fruit ); Here is my SQL query $search_criteria = "" . "SELECT c.* " . "FROM customers AS c LEFT JOIN type AS p ON c.customer_id= p.customer_id" . "WHERE type NOT IN ('$fruit_types ') " . "GROUP BY c.customer_id, p.customer_id" . "ORDER BY customer_id Asc"; This works if I Just use IN for the customers i want to find that have purchased a particular type of apple but i am trying to search for customers that have never purchased a particular apple or multiple apples from my list. For example if i select just macintosh from the list customer 1 still show up as not purchasing that apple type because they have purchased an apple that is not a macintosh. Can anyone help me figure out how i accomplish this task?
  2. A question answered with a non helpful question. I used to use this forum several years ago and never had such ignorant comments from users. Thanks to those that have been trying to help. I think i will have to go to a forum where users understand people can be ignorant and need help..
  3. If you are not going to aid in teaching don't comment Being an A****ole does not help. Im no guru and i come here for help not to listen to people like you. Stay off my post.
  4. This is producing results for me however it is still not giving me results where every item selected has to be associated with the id. It still produces results if any of the id's have the selected items. $fruit_count = count($_POST['fruit']); $fruit_types = join("','",$_POST['fruit']); $fruit_results = $conn->query(" SELECT id FROM fruit WHERE fruit_name IN ('$fruit_types') GROUP BY id HAVING COUNT(1) = count($fruit_count) ");
  5. Jacques1 You comment is not of assistance with the actual resolution to my problem. please feel free to assist me with the actual question or i would appreciate you not post at all. I am here seeking assistance not insult. Is anyone else able to offer some assistance?
  6. I understand the injection is there and i posted a quick and dirty to avoid posting any other code. I have seen the exact code you have replied with on google and have tried using it already. If apple and banana are selected from my multiple selection I should only get id 1 and id 2 using my while statement. I think i have modified the code to represent what i need. The final number 3 you posted is a dynamic number depending on the amount of fruit type selected. When i try to echo the results i get a an error: $fruit_results = $conn->query("SELECT id FROM fruit WHERE fruit_name IN ('$fruit_type ') GROUP BY id HAVING COUNT(1) = count('$fruit_type ')"); while($row = $fruit_results ->fetch_assoc()) { echo $row['id']; } Call to a member function fetch_assoc() on boolean
  7. I have searched this on google and this forum and and struggling to figure this out. I have a table: | id | fruit_name | The id column is not unique i have several identical enstries and the name is also not unique and has several identical entries: | 1 | apple | | 2 | banana | | 2 | apple | | 1 | orange | | 3 | grapefruit | | 3 | apple | | 1 | banana | | 2 | peach | | 3 | peach | I have a multiple select list with the id="fruit" and using join to create a variable for my query: $fruit_type = join("','",$_POST['fruit']); $fruit_results = $conn->query("SELECT * FROM fruit WHERE fruit_name IN ('$fruit_type ')"); while($row = $fruit_results ->fetch_assoc()) { echo $row['id']; } This is giving me all the id of any row that has any type of fruit that is selected in the list. I am trying to the id's that contain all of the fruit selected not just one or the others. Can anyone help me out please? Thanks, Halisco
×
×
  • 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.