TheStalker Posted December 3, 2008 Share Posted December 3, 2008 Hi guy im wondering if you can help or have any ideas. I have a table that shows details from a database(all of them atm), what i want is A-Z links running acroos the top of the table. When a letter is picked, say the letter A i want to display all the records that have peoples surnames that start with the letter A. now i know how i would go about this using a form to sumit from say a combo box or a text box but not doing it like this. i Know the SQL is going to be somthing like SELECT col FROM table WHERE col LIKE 'A%' Im guessing i need to replce the A with a varible that has stored what ever letter the user has click e.g. SELECT col FROM table WHERE col LIKE '$letter'%' but how do i get the letter into the VAR from just the link being clicked????? This is the code i have atm $sql= mysql_query("SELECT* FROM table WHERE link ='1' ORDER BY surname ASC"); ?> <table border='1' width =''> <tr class=""> <th>surname</th> <th>Ref</th> <th>D.O.B</th> </tr> <?php while($row = mysql_fetch_array($sql)) { echo "<tr class='" .altrow. "'>"; echo "<td> ". $row['surname'] . "</td>"; echo "<td><center>" . $row['Ref'] . "</td>"; echo "<td>" . $row['dateOfBirth'] . "</td>"; echo "</tr>"; } ?> </table> Any help or idea on how to do this would be great Quote Link to comment https://forums.phpfreaks.com/topic/135344-solved-a-z-links-to-display-data-help-pls/ Share on other sites More sharing options...
TheStalker Posted December 3, 2008 Author Share Posted December 3, 2008 ok i think ive found out where ive been going wrong below is the code that worked just incase someone else searches this at a later date <a href ="test.php?selection=A">A</a> <a href ="test.php?selection=B">B</a> <a href ="test.php?selection=C">C</a> <a href ="test.php?selection=D">D</a> <a href ="test.php?selection=E">E</a> <a href ="test.php?selection=F">F</a> <a href ="test.php?selection=G">G</a> <a href ="test.php?selection=H">H</a> <a href ="test.php?selection=I">I</a> <a href ="test.php?selection=J">J</a> <a href ="test.php?selection=K">K</a> <a href ="test.php?selection=L">L</a> <a href ="test.php?selection=M">M</a> <a href ="test.php?selection=N">N</a> <a href ="test.php?selection=O">O</a> <a href ="test.php?selection=P">P</a> <a href ="test.php?selection=Q">Q</a> <a href ="test.php?selection=R">R</a> <a href ="test.php?selection=S">S</a> <a href ="test.php?selection=T">T</a> <a href ="test.php?selection=U">U</a> <a href ="test.php?selection=V">V</a> <a href ="test.php?selection=W">W</a> <a href ="test.php?selection=X">X</a> <a href ="test.php?selection=Y">Y</a> <a href ="test.php?selection=Z">Z</a> <a href ="test.php">All</a> $selection = $_GET['selection']; $sql = mysql_query("SELECT* FROM table WHERE surname LIKE '$selection%' AND link ='1' ORDER BY surname ASC"); The rest of the code is the same as in my first post Quote Link to comment https://forums.phpfreaks.com/topic/135344-solved-a-z-links-to-display-data-help-pls/#findComment-704985 Share on other sites More sharing options...
.josh Posted December 3, 2008 Share Posted December 3, 2008 <?php foreach(range('A','Z') as $letter){ echo "<a href ='test.php?selection=$letter'>$letter</a> "; } Quote Link to comment https://forums.phpfreaks.com/topic/135344-solved-a-z-links-to-display-data-help-pls/#findComment-704989 Share on other sites More sharing options...
TheStalker Posted December 3, 2008 Author Share Posted December 3, 2008 <?php foreach(range('A','Z') as $letter){ echo "<a href ='test.php?selection=$letter'>$letter</a> "; } This is a much better way then mine of getting the A-Z to display. Could you apply css to where each letter sits on the webpage tho? cheers Quote Link to comment https://forums.phpfreaks.com/topic/135344-solved-a-z-links-to-display-data-help-pls/#findComment-704997 Share on other sites More sharing options...
.josh Posted December 3, 2008 Share Posted December 3, 2008 what, you mean like, adding id='blah' or class='blah' inside the anchor tag? Or wrapping each one in some div tag or something, where there is css associated with it? Yes. PHP parses code on the server and spits the results out as plain old text. As far as the client is concerned, it looks exactly like you did it. CSS is done clientside. Quote Link to comment https://forums.phpfreaks.com/topic/135344-solved-a-z-links-to-display-data-help-pls/#findComment-705009 Share on other sites More sharing options...
TheStalker Posted December 3, 2008 Author Share Posted December 3, 2008 im pretty new to css was planning on using <p> around mine. cheers for the help ill have a mess around with it all Quote Link to comment https://forums.phpfreaks.com/topic/135344-solved-a-z-links-to-display-data-help-pls/#findComment-705014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.