SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 33 of 33
  1. #26
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,996
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by RedBishop View Post
    thank you so much for helping me and for explaining what the code is doing.
    No problem. I'm just happy to help

    Quote Originally Posted by RedBishop View Post
    It won't let me select a checkbox from "fruit" and a checkbox from "price", so that the query is && fruit='melon' && price='expensive'.
    Could you elaborate on this. What won't let you select a checkbox?
    Are the values being passed to your PHP script correctly?
    In other words, is the problem in the JS or in the PHP?

  2. #27
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm unable to refine my selection by selecting multiple checkboxes. So if I click the melon checkbox it will display all the melons, but if I then click expensive to show only expensive melons it won't let me do that. It will add the price="expensive" conditional to the original query and not to the one that has already been filtered.

    The PHP is working fine with JavaScript disabled.

  3. #28
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,996
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Every time one of the check boxes is selected, your script should be firing an AJAX request to the PHP script.
    Based on what parameters it was passed, the PHP script should be assembling a query and executing it.
    It should then be returning the results of the query to the JavaScript which should be displaying the results on the page.

    From what you describe above, it seems that the query is only executing once and that subsequent changes to the check boxes are having no effect.
    Are you sure you have implemented things as described above?

  4. #29
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I don't why. I've posted the PHP code below.




    PHP Code:
    if (isset($_POST['fruit'])){

    foreach (
    $_POST['fruit'] as $f) {
              
    $arguments[] .= "fruit='$f'";
        }
            }
    if (isset(
    $_POST['price'])){        
    foreach (
    $_POST['price] as $p) {
              $arguments[] .= "price='
    $p'";
        }        
    }


    if(!empty($arguments)) {
      $conditions = implode(' 
    && ',$conditions);


  5. #30
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From what I can see - yes. I've added this to the Ajax call.

    success: function(response){
    $("#container").html(response)
    }

  6. #31
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,996
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    OK, well something is going wrong somewhere.
    I'll send you a PM.

  7. #32
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok Pullo,

    thanks a lot.

  8. #33
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,996
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Just to be complete, I wrote this up as a tutorial.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •