Jump to content

Selection Algorithm


neo777ph

Recommended Posts

i had a used a drop list form field to show data coming from the database..

user should select one item from the droplist before he/she submits the page.

example:

<select name="employee">
<?php
$strsql = "Select name,empid,vendorid,idemp from people where usercode = 'EMP' and local = '$local' order by name";
$result = mysql_query($strsql);// this query retrieves about 500 records
$numrows = mysql_numrows($result);
if ($numrows > 0) {
$i = 0;
while($i<$numrows){
	$employee = mysql_result($result,$i,"name"); 
	$employeeid = mysql_result($result,$i,"empid"); 
	$vendorid = mysql_result($result,$i,"vendorid"); 
	$idemp = mysql_result($result,$i,"idemp"); 
	echo "<option value='$idemp'>$employee - $employeeid - $vendorid</option>";
$i++;
}
}
?>

</select>

 

However this form method is inefficient when i have to retrieve 500 records and list them on the droplist.

Users of the system would look first on those 500 enlisted on the drop list..Even though i sorted it out..It still takes time for them to select the proper one on the droplist.

 

My solution for the problem is to have a form field that acts like this..

if a user types on the input field "al":

the field would shown all on the list that starts with "al"

note: that the entry on the list camed from the database..

 

Hope I had delivered my point correctly..This implementation would faster our processing..

how can i do this algorithm?

 

HELP -- the beatles asked for it..so am i.. =>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/40809-selection-algorithm/
Share on other sites

You can change the query like this:

 

$strsql = "Select name,empid,vendorid,idemp from people where usercode = 'EMP' and local = '$local' and name ilike '$prefix%' order by name";

 

"ilike" does case-insensitive matching, "like" does case sensitive matching.  $prefix is the variable for your new form field.

Link to comment
https://forums.phpfreaks.com/topic/40809-selection-algorithm/#findComment-197586
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.