Topic awaiting preservation: Sort by last name (PHP - MySQL) (Page 1 of 1) |
|
---|---|
Maniac (V) Inmate From: there...no..there..... |
posted 11-21-2006 17:08
continuing from here : Auto refresh page after delete from db code: //sorting query. User chooses a branch and sorts the names according to branch. if(isset($_POST['sort'])){ //check to see if the button was pushed switch($_POST['location']){ case "Greensboro": $query = "SELECT * FROM contact WHERE location = 'Greensboro' ORDER BY lastname ASC"; break; case "Hickory": $query = "SELECT * FROM contact WHERE location = 'Hickory' ORDER BY lastname ASC"; break; default: $query = "SELECT * FROM contact ORDER BY lastname ASC"; } }else{ $query = "SELECT * FROM contact ORDER BY lastname ASC"; }
|
Lunatic (VI) Inmate From: under the bed |
posted 11-21-2006 19:04
something along these lines - |
Maniac (V) Inmate From: there...no..there..... |
posted 11-21-2006 22:35
ah...very good. I'll switch that around to pull the location in from a variable. Do the same for the letters. code: <form action="index.php" method="post"> <select name="location"> <option value="all">All</option> <option value="Greensboro">Greensboro</option> <option value="Hickory">Hickory</option> </select> <input type="submit" name="sort" value="Go" /> </form>
code: <a href="index.php?lastname=A">A</a>
|
Lunatic (VI) Inmate From: under the bed |
posted 11-22-2006 01:24
Yep, that's about it. =) |
Maniac (V) Inmate From: there...no..there..... |
posted 11-22-2006 03:31
groovy. Thanks for the help. Starting to get the hang of this PHP / MySQL stuff. Slowly...but getting there |
Maniac (V) Inmate From: there...no..there..... |
posted 11-27-2006 16:54
OK, I'm back to working on this. I have it working sort of I guess. Here is what I have. code: switch ($_GET['alpha']) { case "A": $query = "SELECT * FROM contact WHERE lastname LIKE \"A%\" ORDER BY lastname ASC"; }
code: <a href="index.php?alpha=A">A</a>
|
Lunatic (VI) Inmate From: under the bed |
posted 11-27-2006 18:43
I'm not following you. Why do you need to know when it is clicked? The link will relaod the page, with the correct parameter sent via the url. |
Maniac (V) Inmate From: there...no..there..... |
posted 11-27-2006 22:50
Maybe I was not understanding what you were telling me here. quote:
|
Lunatic (VI) Inmate From: under the bed |
posted 11-28-2006 00:24
Ah, ok. |
Maniac (V) Mad Scientist From: :morF |
posted 11-28-2006 01:08
Also, you don't need to use a 26-character long set of switch cases to achieve this. First, you'd check if the input is an alpha character using: code: if(ereg('[A-Za-z]',substr($_GET["alpha"],0,1))) { $query = "SELECT * FROM contact WHERE lastname LIKE '".strtoupper(substr($_GET["alpha"],0,1))."%' ORDER BY lastname ASC"; } else { $query = NULL; }
|
Maniac (V) Inmate From: there...no..there..... |
posted 11-28-2006 01:29
nah, that clarified it DL. Thanks =) |
Lunatic (VI) Inmate From: under the bed |
posted 11-28-2006 19:28
(just for the record ) quote: |
Maniac (V) Mad Scientist From: :morF |
posted 11-29-2006 07:43
Heh, yeah, I know, DL-44... CPrompt just didn't seem to have seen it, so I posted an example. |