I can display an alpha index of the table contents using a form as follows:

if (isset($_POST['name'])) $name = ($_POST['name']);
else $name = "no name entered";

<form method="post" name="search" action="directory.php"/>
        <font family = "arial,verdana,sans-serif" color="#3F7cef"size="4"/>Select Letter</font>
        <input type="text" name="name" size="5" maxlength ="1"  value="<?php if(isset($_POST['name'])){echo htmlentities($_POST['name']);}?>" />
        <input type="submit" name="submit" value="submit" alt="search"/> 

if($name== "")
echo "<p><font color='red' size='6px'>You have not entered a name</font></p>";
echo"<br />";
echo "<font color='#3F7cef'size='4'/>You searched for:</font>";
echo "<p>";
echo "<font color='#3F7cef'size='6'>";
require_once "../php/fix_it.php";
echo fix_it($name);                              //function to return name input
require_once '../php/dbconnect.php';                                
$query = "(SELECT name1 FROM allnames WHERE name1 LIKE '$name%')UNION(SELECT name2 FROM allnames WHERE name2 LIKE '$name%')UNION(SELECT name3 FROM allnames WHERE name3 LIKE '$name%').....UNION(SELECT name17 FROM allnames WHERE name17 LIKE '$name%')ORDER BY 1";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
                       /* some code omitted  */

while($row = mysql_fetch_assoc($result)){
$array= $row;
foreach($array as $var){

I would really like to replace the FORM with a line 'A' 'B' 'C' 'D' etc then onclick on a letter would initiate the SELECT query and print the index.
I am told this can only be done with JavaScript or Ajax neither of which I know. I this the only way ? If so could someone describe what it involves and give some pointers?

4 Years
Discussion Span
Last Post by furlanut

Thanks. I have looked at Ajax/Javascript but think I will stay with PHP. However in neither have I been able to work out how to assign variable $name to the letter clicked (A,B C etc) when no form input is used.
At the moment I am only able to display ALL records at once !

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.