Web Analytics Made Easy -
StatCounter Is there an easier way? - CodingForum

Announcement

Collapse
No announcement yet.

Is there an easier way?

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

  • Is there an easier way?

    Hi,

    I was wondering if anybody had any ideas how to structure this. I have a list of records that can be sorted by name, however, i want to put # - A -B - C - D - E.... etc... (all the letters of the alphabet) so that if the user clicks on "C" it shows everything the starts with "C", now my idea (but i dont think its the best way) was to have a $_GET for all the letters, like i said, does anybody have an easier way?

    Thank you in advance

  • #2
    If I understood you correctly, I would do it this way, too.
    www.united-scripts.com
    www.codebattles.org

    Comment


    • #3
      Your way sounds simpler than mine, if it was in a database could your query be

      SELECT * FROM table WHERE beginningletter = $_GET[letter]
      Dave

      Comment


      • #4
        PHP Code:
        <?php
        $table 
        "bob";
        $fieldname "hello";
        $sql "SELECT * FROM $table WHERE $fieldname LIKE '" $_GET["letter"] ."%'";
        ?>
        sample link:

        Code:
        ..<a href="script.php?letter=B>B</a>--<a href="script.php?letter=C">C</a>--<a href="script.php?letter=D>D</a>--...

        i think that will work.

        Comment


        • #5
          oh...where/how are the records stored?

          Comment


          • #6
            If writing the links by hand seems cumbersome, you might consider generating them by a script:

            PHP Code:
            $letters range('A''Z');
            for (
            $i 0$i count($letters); $i++) {
                print 
            ' <a href="page.php?letter=' $letters[$i] . '">' $letters[$i] . '</a> -';

            De gustibus non est disputandum.

            Comment


            • #7
              what if i want to add a "#" for other things....will it complicated things?

              Comment


              • #8
                Not really. You just have to sort-of inverse the select statement:

                Code:
                SELECT fields FROM records WHERE field NOT RLIKE "^[a-z]";
                De gustibus non est disputandum.

                Comment


                • #9
                  how about saying, LIKE 'numbers'

                  is there something i can write so that it understands that it means numbers? instead of writting NOT LIKE.......cuz im getting problems on getting it to work

                  Comment


                  • #10
                    don't worry, i figured out a way, and i solved my inital problem, thanx for the help

                    Comment

                    Working...
                    X