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