Jump to content

Help with array and SQL statement


sdotsen

Recommended Posts

Came across the following tutorial.

 

http://www.gadgetopia.com/autosuggest/

 

Works great and I got it to read from my mysql DB. However, if I have "John Brown" stored in the array, it works fine and shows up in the dropdown if you type the letter "J." However, if you type in B, it doesnt bring it up. Any way to do this or am I basically out of luck?

 

The following is my SQL statement to pull the usernames.

 

$sql = "select f_name, l_name from contacts";
$result = mysql_query($sql);
$num_results = mysql_num_rows($result);

$test_array = array();

while($myrow = mysql_fetch_array($result)) // grabs number of users to email from associated list
{
  $haha = $myrow['f_name'];
  $haha2 = $myrow['l_name'];
  
  $haha3 = "$haha $haha2";
  
  //array_push($test_array, $myrow['f_name']);
  array_push($test_array, $haha3);
}

 

So in the drop down it'll print out "John Brown." Maybe the sample code I found in the link I mentioned in the beginning is limited. I've tried other "auto suggest" scripts and they were either too hard to modify or it didnt do that great of a job.

Link to comment
Share on other sites

Do you want "John Brown" to show up when you press B?  If so, that'll require modification of the javascript rather than your php.  That's because it's the javascript that decides which strings to display when you press a letter.

Link to comment
Share on other sites

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.