Web Analytics Made Easy -
StatCounter letter paging (almost there) - CodingForum

Announcement

Collapse
No announcement yet.

letter paging (almost there)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • letter paging (almost there)

    This is my situation. I have one page that is like a search results page for around 5 different types of ways a user can search for records. lets say a user searches by type (which is one of my searches)--> to be able to click on a letter, like G, and narrow down the search by those records that start with the letter G.

    However,

    another user might search by type and location--> that would give different results. and i want the same time as above.

    The way i have it now, if the user clicks on G, it'll show ALL the records that start with G, regardless of the search results showing on the page. So what im hoping is to have a code that says: (user clicks on G) narrow these records (the ones on the page) that start with the letter G.

    this is what i have, but it doesnt narrow down the search, it shows ALL the records, now i thought, what if this code simply adds itself to the url, for example....www.site.com/type=food&letter=c.

    whereas how i have it now is www.site.com/letter=c --> thats why it's sorting through ALL the records....

    PHP Code:

    <?php $letters range('A''Z');  
    for (
    $i 0$i count($letters); $i++) {  
        print 
    ' <a href="list.php?letter=' $letters[$i] . '">' $letters[$i] . '</a> -';  
    }
    ?>
    thank you

  • #2
    I'm not sure how your query is set up, but I would keep an array of search criteria. Whenever a new letter is selected or whatever, you add this to the array, refresh the page, and when you re-query the database, you include each the elements of this array in your WHERE clause.

    At first glance, that's the way I'd do it. If this doesn't work for you, you'll have to give a little more information (especially regarding why not.)

    Hope that helps,
    Sadiq.

    Comment


    • #3
      here is my query, i already added the $_GET['letter']....if the code looks weird or outdated, its because i work with DreamWeaver, which generates the code for me....thanx

      PHP Code:

      SELECT 
      *
      FROM listing
      WHERE type 
      'coltype' OR name LIKE '%quicksearch%' OR 
      (
      type 'coltype' AND name LIKE 'letter%') OR 
      (
      address 'estaddress' AND type 'esttype' AND location 'estlocation') OR  
      (
      address 'estaddress' AND type 'esttype' AND location 'estlocation' AND name LIKE 'letter%') OR 
      (
      location 'locationbutton' AND type 'locationtype') OR 
      (
      location 'locationbutton' AND type 'locationtype' AND name LIKE 'letter%') OR 
      (
      name LIKE '%partialname%' AND type 'partialtype') OR  
      (
      name LIKE '%partialname%' AND type 'partialtype' AND name LIKE 'letter%') OR 
      (
      type LIKE '%advtype%' AND music LIKE '%advmusic%' AND location LIKE '%advlocation%' AND events LIKE '%advevents%' AND food LIKE '%advfood%') OR 
      (
      type LIKE '%advtype%' AND music LIKE '%advmusic%' AND location LIKE '%advlocation%' AND events LIKE '%advevents%' AND food LIKE '%advfood%' AND name LIKE 'letter%')
      ORDER BY sqlorderby 
      Last edited by grudz; Feb 18, 2004, 12:57 PM.

      Comment


      • #4
        I'm not sure if you read my full posting, but anyway...

        How else can the listing be narrowed? Only by letter?

        Then I would keep an array and add to it whenever the user clicks a letter.

        You can call the array letters, and use the explode/implode functions to deal with it and pass it between views. Then when you're creating your select statement (you'll have to re-organize it slightly..), you'll need to loop through this array when creating the WHERE clause.

        If there are other ways to narrow the listing, I think you should create another array for them, or see if you can work them all into the same array, amd use the same technique.

        If that doesn't make sense, post your questions.

        Good luck,
        Sadiq.

        Comment


        • #5
          im sorry, i thought my post could help you....anyway.... im not knowledgable enough to understand what u just said, i know what certain terms mean, but when it comes down to writing my own, thats a problem for me. I know what i know in PHP, but thats not much, everytime i have to do something, i have to learn it, then apply it, which takes a toll on me. So if there's a way you could direct me to what you mean, that would be greatly appreciated, if not, just say so.....

          thanx so far

          Comment


          • #6
            I see...

            Well I don't want to write the whole thing out for you, and I don't know of a resource off hand that could help you either.

            I would suggest reading the following pages over to understand the explode and implode terms:



            If the array idea is applicable. I would like a little more detail as to how a user would be able to narrow down a search. I'm not sure I understand what you mean by (in your first post) :
            another user might search by type and location--> that would give different results. and i want the same time as above.
            same time? or same thing?

            Please expand on that, because it just occured to me that you can't pick more than one letter at a time (or can you?).

            Sadiq.

            Comment


            • #7
              thing....sorry thats what i meant......

              and once they enter the page through a search method.....i want them to be able to narrow those results by any letter....and it's only one letter..... for example......

              i have 3 records.....

              dog
              cat
              sheep

              the search results gives me 2 records

              dog
              sheep

              if i click on C, its NOT supposed to give a record (because "cat" wasnt wasnt one of my results)......the way i have it now....it'll give me "cat" because it goes through ALL the records.....

              Comment


              • #8
                ok, so what's the problem right now?

                You've got a lot of code, what's wrong with it? What is it doing, what is it not doing?

                I'm figuring that you've got a search page, and the results page displays all correctly. However, when the user clicks a letter, it displays ALL records for that letter? Not just the records that correspond with the search AND the letter. Is that right?

                In that case, I'm seeing that you're only passing the letter through when the user clicks the letter. You have to ALSO pass all the search critera though to display that subset.

                So where you've got that
                PHP Code:
                <a href="results.php?letter=".$letter."type=".$type........ 
                And put them all on that line.

                Let me know how that works out,
                Sadiq.

                Comment


                • #9
                  [QUOTE]Originally posted by sad69


                  So where you've got that
                  PHP Code:
                  <a href="results.php?letter=".$letter."type=".$type........ 

                  i just thought of something....what if there could be a code that simply adds "&letter=$letter" to the url, wouldnt that make sense?

                  because the url will always be different (because there will be different searches) so i cant just say add this: "<a hreaf="results.php?letter=$letter&type=type...."
                  Last edited by grudz; Feb 18, 2004, 02:15 PM.

                  Comment


                  • #10
                    Depends, I don't how the whole thing works.

                    But I always say, "Go with whatever works." Try it out, I'm praying for you!

                    Good luck,
                    Sadiq.

                    Comment


                    • #11
                      but it doesnt work........i was asking you if you knew a way to write "add to url &letter=$letter"

                      Comment


                      • #12
                        Do you have the url?

                        Also, and I don't know if it'll make a difference or not, in your original form, is the method=post or get?

                        If you have the url, say it's stored in $url, you would just do:
                        PHP Code:
                        $url .= "?letter=".$letter
                        If you don't have the url, but know what your page.php is called, and if your method=get in your form, then you may be able to do something like this:
                        PHP Code:
                        $url "something.php?";
                        foreach(
                        $_GET as $var => $val) {
                         if(
                        strcmp($var"letter") == 0) { //skips letter to be added with new value
                          
                        continue;
                         }
                         
                        $url .= $var."=".$val;
                        }
                        $url .= "letter=".$letter
                        I haven't tested that code, but it should do something like what you need?

                        Sadiq.

                        Comment


                        • #13
                          ok.....i think we're getting somewhere.....

                          first when u say this...
                          Do you have the url?
                          does that mean whats the address of MY site...the one im working on?

                          second is this code
                          [quote]
                          PHP Code:

                          $url 
                          "something.php?";
                          foreach(
                          $_GET as $var => $val) {
                           if(
                          strcmp($var"letter") == 0) { //skips letter to be added with new value
                            
                          continue;
                           }
                           
                          $url .= $var."=".$val;
                          }
                          $url .= "letter=".$letter
                          [quote]

                          simply going to add &letter=value to the url?

                          because the page that displays the search results always stays the same (list.php) but after that, itll depend on what the search is.....

                          and it uses GET not POST....i need it to use that for another reason....

                          so....we almost getting there ?

                          Comment


                          • #14
                            I think so. Plug in that second piece of code and use <a href="<?php echo $url; ?>"> when you get the letter or whatever and I think that should do it.

                            Try it out and let me know what happens.

                            Sadiq.

                            Comment


                            • #15


                              $url = "something.php?";
                              foreach($_GET as $var => $val) {
                              if(strcmp($var, "letter") == 0) { //skips letter to be added with new value
                              continue;
                              }
                              $url .= $var."=".$val;
                              }
                              $url .= "letter=".$letter;
                              ok......so i added this...and changed something.php to my page (list.php)...do i have to change anything else?

                              Comment

                              Working...
                              X