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
https://forums.phpfreaks.com/topic/46672-help-with-array-and-sql-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.