Jump to content

Phone list simple search by name


leo7068

Recommended Posts

I have inherited a page from a coder I do not have contact to. He had a search button on the bottom of this phone list, that never worked, but now I must make it work. The phone list uses this code to show the 150 or so Names, Ext.ension numbers, and Locations of people. This array works fine and displays fine. Using the search dialog displays an empty array no matter the inputted search. I would simply like to type in a search for "John Doe" and have the results show the Name, Ext. number and location of only matching search results. This could be by either displaying matches or hiding/filtering non-matches.

 

<?	include($_SERVER['DOCUMENT_ROOT']."/inc/forms.inc.php");
if(isset($_POST['module'])){$perms=Utilities::CheckPermissionsADMN($_POST['module']);}else{$perms=Utilities::CheckPermissionsADMN($_GET['module']);}
if(isset($_POST['module'])){$permsB=Utilities::CheckPermissionsRW($_POST['module']);}else{$permsB=Utilities::CheckPermissionsRW($_GET['module']);}
if($perms)$itOnly="(itOnly='1' OR itOnly='0')";else $itOnly="itOnly='0'";
if(!$perms)$itOnly1="AND name!='zzz'";else $itOnly1="";
$res=mysql_query("SELECT * FROM Data_ColorCodes WHERE title!='Mr. B' ORDER BY title ASC",Config::getDbLink());
$x=0;
while($dat=mysql_fetch_array($res)){$list[$x]=$dat['colorCode'];$list1[$x++]=$dat['title'];}
if(isset($_POST['numDisp']))$paging=$_POST['numDisp'];else $paging=30;
if($_POST['pageNum']=="")$pageNum=0;else $pageNum=$_POST['pageNum'];
if($_POST['searching']==1 and $_POST['searchName']!="" and $_POST['searchName']!="zzz"){
	$res=mysql_query("SELECT * FROM BAPhoneList WHERE name LIKE '%".$_POST['searchName']."%' $itOnly1 AND $itOnly",Config::getDbLink());
	$result=mysql_query("SELECT * FROM BAPhoneList WHERE name LIKE '%".$_POST['searchName']."%' $itOnly1 AND $itOnly ORDER BY itOnly ASC,name ASC LIMIT ".$pageNum*$paging.",".$paging,Config::getDbLink());
}else{
	if(!$perms)$out="zzz";else $out="";
	$res=mysql_query("SELECT * FROM BAPhoneList WHERE itOnly='0'",Config::getDbLink());
	$result=mysql_query("SELECT * FROM BAPhoneList WHERE itOnly='0' ORDER BY itOnly ASC,name ASC",Config::getDbLink());
	if($perms){
		$res1=mysql_query("SELECT * FROM BAPhoneList WHERE itOnly='1'",Config::getDbLink());
		$result1=mysql_query("SELECT * FROM BAPhoneList WHERE itOnly='1' ORDER BY itOnly ASC,name ASC",Config::getDbLink());
	}
}
$start=$pageNum*$paging;
$end=$start+$paging;
while($data=mysql_fetch_array($result)){
	if(is_numeric($data['name'])){
		$r=mysql_query("SELECT * FROM BAUserList WHERE id='".$data['name']."'",Config::getDbLink());
		$d=mysql_fetch_array($r);
		$name=$d['firstName']." ".$d['lastName'];
	}else{$name=$data['name'];}
	if($name=="")$name="zzz";
	$toList[]=array('name'=>$name,'ext'=>$data['extNumber'],'port'=>$data['portNumber'],'location'=>$data['location'],'status'=>$data['status'],'extraInfo'=>$data['extraInfo']);
}
foreach($toList as $key=>$row){$volume[$key]=$row['name'];}
array_multisort($volume,SORT_ASC,$toList);
if($perms){
	while($data=mysql_fetch_array($result1)){
		if(is_numeric($data['name'])){
			$r=mysql_query("SELECT * FROM BAUserList WHERE id='".$data['name']."'",Config::getDbLink());
			$d=mysql_fetch_array($r);
			$name=$d['firstName']." ".$d['lastName'];
		}else{$name=$data['name'];}
		if($name=="")$name="zzz";
		$toList[]=array('name'=>$name,'ext'=>$data['extNumber'],'port'=>$data['portNumber'],'location'=>$data['location'],'status'=>$data['status'],'extraInfo'=>$data['extraInfo']);
	}
}
if($end>sizeof($toList))$end=sizeof($toList);
?>												<table cellspacing="1" cellpadding="0" width="100%" border="0">
												<tr><td height="21" class="TableSectionTop" colspan="5" align="center" nowrap><strong>Phone List</strong></td></tr>
												<tr>
<? if($perms){?>														<td class="SectionHeader" style="width:45px;">Port #</td><? }else{?>
													<td class="SectionHeader" style="width:45px;">Ext. #</td><? }?>
													<td class="SectionHeader">Name</td>
<? if($perms){?>														<td class="SectionHeader" style="width:45px;">Ext. #</td>
													<td class="SectionHeader">Location</td>
													<td class="SectionHeader">Status</td><? }else{?>
													<td colspan="3" class="SectionHeader">Alt. Number</td><? }?>
												</tr>
<? for($x=$start;$x<$end;$x++){?>													<tr class="SectionList" onmouseover="this.className='SectionListOver';" onmouseout="this.className='SectionList';"<? if($perms or $permsB){?>onclick="googlewin=dhtmlwindow.open('googlebox','iframe','/modules/phonelist/inc/admin.modify.php?uid=<?=$toList[$x]['port'];?>','Port # <? if($toList[$x]['port']<=192)echo $toList[$x]['port'];else echo"";?>','width=590px,height=450px,center=1,resize=0,scrolling=1','recal'); return false" style="cursor:pointer;color:#000;background:#FFF;"<? }else{?> style="cursor:default;color:#000;background:#FFF;"<? }?>>
<? if($perms){?>														<td nowrap><p style="padding-left:3px;"><? if($toList[$x]['port']<=192)echo $toList[$x]['port'];else echo"";?> </p></td><? }else{?>
													<td nowrap><p style="padding-left:3px;"><?=$toList[$x]['ext'];?> </p></td><? }?>
													<td width="300px" nowrap><p style="padding-left:3px;"><? if($toList[$x]['name']=="zzz")echo"";else echo $toList[$x]['name'];?> </p></td>
<? if($perms){?>														<td nowrap><p style="padding-left:3px;"><?=$toList[$x]['ext'];?> </p></td>
													<td nowrap><p style="padding-left:3px;"><?=$toList[$x]['location'];?> </p></td>
													<td nowrap><p style="padding-left:3px;"><?=$toList[$x]['status'];?> </p></td><? }else{?>
													<td colspan="3" nowrap><p style="padding-left:3px;"><?=$toList[$x]['extraInfo'];?> </p></td><? }?>
												</tr><? }?>
											</table><br><br>
<? if($_POST['searching']!=1){?>
<?=pagination($_POST['module'],$_POST['page'],$paging,$pageNum,mysql_num_rows($res)+mysql_num_rows($res1));?>
											<form action="" method="post" style="display:inline">
												<?=FormHiddenField("module",$_POST['module']);?>
												<?=FormHiddenField("page",$_POST['page']);?>
												<?=FormHiddenField("numDisp",$paging);?>
												<?=FormHiddenField("pageNum","0");?>
												<?=FormHiddenField("searching","1");?>
												<?=FormTextBoxID("searchName","",256,"200px");?>
												<?=FormTextSubmit("sent_data","Search");?>
											</form><? }?>

Link to comment
Share on other sites

This helped me narrow the problem. One simple question now:

 

All of the "name" entries have a space between the first and last name. When I do a

$sresult = mysql_query("SELECT * FROM BAPhoneList WHERE name LIKE 'Bob*'"); 

I get 1 result for "Bob" who does not have a last name or space, but for "Bob Brown" and "Bob Smith" the results do not show.  I also tried using

'%Bob_%'

'%Bob'

'Bob%'

'%Bob%' 

but these did not work. How do I write this code so that it is able to show all 3 Bob's and not just the "first name only" Bob?

Link to comment
Share on other sites

Would I put it here:

while($data=mysql_fetch_array($result)){
	if(is_numeric($data['name'])){
		$r=mysql_query("SELECT * FROM BAUserList WHERE id='".$data['name']."'",Config::getDbLink());
		$d=mysql_fetch_array($r);
		$name=$d['firstName']." ".$d['lastName'];
	}else{$name=$data['name'];}
	if($name=="")$name="zzz";		$toList[]=array('name'=>$name,'ext'=>$data['extNumber'],'location'=>$data['location'],'status'=>$data['status'],'extraInfo'=>$data['extraInfo']);
}

Like this:

$searchfilter=’bob’;

while($data=mysql_fetch_array($result)){
	if(is_numeric($data['name'])){
		$r=mysql_query("SELECT * FROM BAUserList WHERE id='".$data['name']."'",Config::getDbLink());
		$d=mysql_fetch_array($r);
		$name=$d['firstName']." ".$d['lastName'];
	}else{$name=$data['name'];}
	if($name=="")$name="zzz";
filter_array('%$searchfilter%")
$toList[]=array('name'=>$name,'ext'=>$data['extNumber'],'location'=>$data['location'],'status'=>$data['status'],'extraInfo'=>$data['extraInfo']);
}

 

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.