Jump to content

Recommended Posts

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 :)

 

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 :)

<?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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.