Help me to use Search String

<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<title>DrLop Report</title>
<script type='text/javascript' src='JS/AJAXControll.js'></script>
<link rel=stylesheet href='CSS/Style.css' type='text/css'>
<link rel=stylesheet href='CSS/Style1.css' type='text/css'>
<script language="javascript">
function fnTagCheckAll(obj, strt_r_no, r_per_page)
{
	objText = document.getElementById("txtValueCollect");
	objText.value = "";

	for(var i=strt_r_no; i < (strt_r_no+r_per_page); i++)
	{
		v = "CB" + i;
		OElement = document.getElementById(v);
		if(OElement != null)
		{
			document.getElementById(v).checked = obj.checked;
			if(document.getElementById(v).checked==true)
				objText.value = objText.value + v + ";";
			else
			{
				str = new String(objText.value);
				str = str.replace(v+";","");
				objText.value=str;
			}
		}
	}
	if(obj.checked == true)
	{
		document.getElementById('DA').style.visibility = 'visible';
		document.getElementById('CA').style.visibility = 'visible';
	}
	else
	{
		document.getElementById('DA').style.visibility = 'hidden';
		document.getElementById('CA').style.visibility = 'hidden';
	}
	//alert(objText.value);
}
function fnTagCheck(obj, r_per_page, min, num_rec)
{
	objText = document.getElementById("txtValueCollect");

	if(obj.checked==true)
	{
		objText.value = objText.value + obj.id + ";";
		str = objText.value;
		count = 0;
		for(var i = 0; i < str.length; i++)
		{
			ch = str.charAt(i);
			if(ch == ';')
				count++;
		}
		if(count == r_per_page || count == (num_rec-min+1))
		{
			document.getElementById('CB').checked = true;
			
			document.getElementById('DA').style.visibility = 'visible';
			document.getElementById('CA').style.visibility = 'visible';
		}
	}
	else
	{
		str = new String(objText.value);
		str = str.replace(obj.id+";","");
		objText.value=str;
		document.getElementById('CB').checked = false;
		
		document.getElementById('DA').style.visibility = 'hidden';
		document.getElementById('CA').style.visibility = 'hidden';
	}
	//alert(objText.value);
}
</script>
</head>
<body>


<div id='light' class='white_content'></div>
<div id='fade' class='black_overlay'></div>
<input name='txtHidden' id='txtHidden' type='hidden' />
<TEXTAREA ID="holdtext" STYLE="display:none;"></TEXTAREA>
<br><br>
<?php
	require_once("func.php");


	$records_per_pg = 100; //if you change it, supply it to display_result call
	$_SESSION["Min"] = 0;

	$global_db = mysqli_connect('dblopp.db.7531756.hostedresource.com', 'dblopp', 'Pol7250', 'dblopp');

//New

	if(!isset($_SESSION["TotalRecords"]))          
	{
		$query = "Select count(*) from cus Where cus  = 'GCL'";
		//$query = "Select count(*) from countrylist where DelFlag = 'N'";
		$result = mysqli_query($global_db, $query) or die("ERROR");
		$lv_Counter = mysqli_fetch_array($result);
		$_SESSION["TotalRecords"] = $lv_Counter[0];
		mysqli_free_result($result);
	}

	if((!isset($_GET['pagenr'])) || (isset($_GET['pagenr']) && $_GET['pagenr'] == 1))
	{
		$pagenr = 1;
		$_SESSION["Min"] = 0;
	}

	if(isset($_GET['pagenr']) && ((int)$_GET['pagenr']) > 1)
	{
		$pagenr = $_GET['pagenr'];
		$_SESSION["Min"] = ($pagenr - 1) * $records_per_pg;
	}

	// You can try the effect of these 2 sets of queries one by one
	// $query = "Select Country_ID, CountryName, CountryAsian, CountryDescription, CountryFlag from countrylist";
	// $query = "Select Country_ID, CountryName, CountryAsian, CountryDescription, CountryFlag from countrylist where DelFlag = 'N'";

	$query = "Select id,date,Time,agt,class,keyw,link,CountryFlag from cus Where cus Like 'GCL'  limit " . $_SESSION["Min"] . ", " . ($_SESSION["Min"] + $records_per_pg);

	// $query = "Select Country_ID, CountryName, CountryAsian, CountryDescription, CountryFlag from countrylist where DelFlag = 'N' limit " . $_SESSION["Min"] . ", " . ($_SESSION["Min"] + $records_per_pg);

	$result = mysqli_query($global_db, $query) or die("ERROR");

	//This is minumum call for pagination of first set of quiries
	//display_result($result, '0');

	//This is a minumum call for pagination of second set of quiries
	//display_result($result, '0', $_SESSION["TotalRecords"]);

	//This is a maximum call for pagination irrespective of quiry type
	
	
	display_result($result, '0', $_SESSION["TotalRecords"], array ('ID','Date','Time','Agent','Classified','Keyword','Link','ST'), 'Status', 100, 1, 1, 1, 1, 1, 1, 1);

	mysqli_free_result($result);
	mysqli_close($global_db);
?>
</body>
</html>

This func.php

<?php
//* 01. $result = mysqli result set (To change mysqli to mysql change the word mysqli with mysql all through the code).
//* 02. $pkey = offset of primary key or any other field in result set that will remain unaltered during editing (i.e. 0 or 1 or 3 etc.).
//# 03. $num_records = total no of records to be displayed.
//  04. $field_names = supply field names as an array. Default original field names.
//  05. $img_header = image column header. Default is: "# Image #".
//  06. $records_per_page = How many records to be displayed in each page (starting from 1). Default is 10.
//  07. $check_col_visible = Check box column is visible or not (1 or 0). Default is 1 (Visible).
//  08. $img_col_visible = Image will be displayed or not (1 or 0). Default is 1 (Visible).
//  09. $edit_col_visible = Edit button column is visible or not (1 or 0). Default is 1 (Visible).
//  10. $del_col_visible = Delete button column is visible or not (1 or 0). Default is 1 (Visible).
//  11. $copy_col_visible = Copy button column is visible or not (1 or 0). Default is 1 (Visible).
//  12. $footer_row_visible = Footer row is visible or not (1 or 0). Default is 1 (Visible).
//  13. $lenone = One character long fields will display CheckBox or not (1 or 0). Default is 1 (CheckBox).

//  [*] -> Always required, [#] -> Require depending on query type.
//  NOTE: PLEASE READ ALL THE COMMENT MARKED EXPLANATION IN THIS FUNCTION AND UNDERSTAND BEFORE USING IT. THANKS.
//New



	function display_result($result, $pkey, $num_records = 0, $field_names = array(), $img_header = "# Image #", $records_per_page = 10, $check_col_visible = 1, $img_col_visible = 1, $edit_col_visible = 1, $del_col_visible = 1, $copy_col_visible = 0, $footer_row_visible = 1, $lenone = 1)
	{
		try
		{
			$tmpresult = $result;
			if($num_records == 0)
			{
				// if $num_records is not supplied at function call
				// if query is: select * from table
				$num_records = mysqli_num_rows($result);
			}
			$num_fields = mysqli_num_fields($result);

			$num_pages = 1;
			if($num_records > $records_per_page)
				$num_pages = ceil($num_records / $records_per_page);

			if(!isset($_GET['pagenr'])) 
				$pagenr = 1;
			else
				$pagenr = $_GET['pagenr'];

			$min = ($pagenr - 1) * $records_per_page + 1;
			$max = $min + $records_per_page - 1;

			echo "<table id = \"HeaderTable\" border=\"0\" align=center><tr><td id = \"HeaderCell\">";
			if($max > $num_records)
				echo "Page: " . $pagenr . "/" . $num_pages . "      Showing: [" . $min . " - " . $num_records . "]/" . $num_records;
			else
				echo "Page: " . $pagenr . "/" . $num_pages . "      Showing: [" . $min . " - " . $max . "]/" . $num_records;
			echo "</td></tr></table>";

			if($check_col_visible == 0)	$check_col = " style=\"display:none\"";
			else				$check_col = " style=\"visibility:visible\"";
			if($img_col_visible == 0)	$img_col = " style=\"display:none\"";
			else				$img_col = " style=\"visibility:visible\"";
			if($edit_col_visible == 0)	$edit_col = " style=\"display:none\"";
			else				$edit_col = " style=\"visibility:visible\"";
			if($del_col_visible == 0)	$del_col = " style=\"display:none\"";
			else				$del_col = " style=\"visibility:visible\"";
			if($copy_col_visible == 0)	$copy_col = " style=\"display:none\"";
			else				$copy_col = " style=\"visibility:visible\"";

			echo "<form id=\"form00\" method=\"post\" action=\"blank.php?pagenr=$pagenr&mode=U\">";
			echo "<a href=\"javascript:delAll(" . $records_per_page . ", " . $pkey . ", " . $num_fields . ", " . $min . ");\" id='DA' style='visibility:hidden;'>[Delete All]</a>&nbsp;&nbsp;<a href=\"javascript:copyAll(" . $records_per_page . ", " . $pkey . ", " . $num_fields . ", " . $min . ");\" id='CA' style='visibility:hidden;'>[Copy All]</a><br>";
			echo "<table id = \"MasterTable\" border=\"0\" align=center>";
			echo "<tr>";
			if(isset($_GET['mode']) && $_GET['mode'] == 'E')
				echo "<th" . $check_col . "><input id=\"CB\" type=\"checkbox\"/ disabled=\"disabled\"></th>";
			else
				echo "<th" . $check_col . "><input id=\"CB\" type=\"checkbox\" onClick=\"javascript:fnTagCheckAll(this," . $min . "," . $records_per_page . ");\" /></th>";
			$footer = '';

        		
			if($field_names == null)
			{
				$fldnms = mysqli_fetch_fields($result);
				foreach($fldnms as $meta)
					echo "<th>" . $meta->name . "</th>";
			}
			else
			{
				for($i = 0; $i < $num_fields; $i++)
					echo "<th>" . $field_names[$i] . "</th>";
			}
			

			echo "<th" . $img_col . ">" . $img_header . "</th>";  // If image controll is added
			echo "<th" . $edit_col . "></th>";  // If Edit button is added
			echo "<th". $del_col . "></th>";  // If Delete button is added
			echo "<th". $copy_col . "></th>";  // If Copy button is added
			echo "</tr>";

			//Make any one assignment comment-marked depending on your query
			$count = 1;	// if query is: select * from table
			$count = $min;  // if query is: select * from table limit startRNo, endRNo
        		$footer = ""; $tdcls = 'tdc2';
			while($row = mysqli_fetch_array($result))
			{
				if($count >= $min and $count <= $max)
				{
					echo "<tr>";
					$CheckBoxID = "CB" . $count;

					if(isset($_GET['mode']) && $_GET['mode'] == 'E')
						echo "<td" . $check_col . " align=\"center\"><input name=$CheckBoxID id=$CheckBoxID type=\"checkbox\" disabled=\"disabled\"/></td>";
					else
						echo "<td" . $check_col . " align=\"center\"><input name=$CheckBoxID id=$CheckBoxID type=\"checkbox\" onclick=\"javascript:fnTagCheck(this," . $records_per_page . ", " . $min . ", " . $num_records . ");\" /></td>";

					$link = ""; $Flg = 0;
					if($tdcls == 'tdc2') $tdcls = 'tdc1'; else $tdcls = 'tdc2';
					for($j = 0; $j < $num_fields; $j++)
					{
						$finfo = mysqli_fetch_field_direct($tmpresult, $j);	//imports the field statistics
						//printf("Name:     %s\n", $finfo->name);
						//printf("Len:      %d\n", $finfo->length);
						//printf("Type:     %d\n", $finfo->type);

						
						if(strlen($row[$j]) > 4 && $Flg == 0)
						{
							$link = strtoupper(substr($row[$j], -4));
							if($link == '.JPG' || $link == '.PNG' || $link == '.GIF')
							{
								$link = $row[$j]; $Flg = 1;
							}
						}

						$tdid = $j . "_" . $count; 
						if(isset($_GET['mode']) && $_GET['mode'] == 'E' && $j != $pkey)
						{
							if(isset($_GET['RNo']) && $count == $_GET['RNo'])
							{
								if($finfo->length > 255)	//######## You can change textarea rows and cols values
									echo "<td align=\"center\"><textarea id=$tdid name=$tdid rows=\"5\" cols=\"20\" value=\"" . $row[$j] . "\" >" . $row[$j] . "</textarea></td>";
								else
								{
									if($lenone == 1 && $finfo->length == 1 && (strtoupper($row[$j]) == 'T' || strtoupper($row[$j]) == 'F' || strtoupper($row[$j]) == 'M' || strtoupper($row[$j]) == 'Y' || strtoupper($row[$j]) == 'N' || strtoupper($row[$j]) == '1' || strtoupper($row[$j]) == '0'))
									{
										$chk = ""; 
										if(strtoupper($row[$j]) == 'T' || strtoupper($row[$j]) == 'Y' || strtoupper($row[$j]) == 'M' || $row[$j] == '1')		$chk = " checked = '1'";
										echo "<td align=\"center\"><input id=$tdid name=$tdid type=\"checkbox\"" . $chk . "></input></td>";
									}
									else
										echo "<td align=\"center\"><input id=$tdid name=$tdid type=\"text\" maxlength=\"" . $finfo->length . "\" value=\"" . $row[$j] . "\" /></td>";
								}
							}
							else
								echo "<td align=\"left\"><span id=$tdid name=$tdid value=\"" . $row[$j] . "\">" . nl2br($row[$j]). "</span></td>";
						}
						else
							echo "<td class='" . $tdcls . "' align=\"left\"><span id=$tdid name=$tdid value=\"" . $row[$j] . "\">" . nl2br($row[$j]). "</span></td>";
						
						$footer = "foot" . $j;
						if($count == 1)
							$footer = 0;
						$footer = $footer + $row[$j];
					}
					if($Flg == 0) $link = "images/NoImage.gif";		//######## You can change img width and height
					
					echo "<td" . $img_col . " align=\"center\"><img alt=\"\" src=\"" . $link . "\" style=\"width:20px;height:20px;\"/></td>";
					echo"<TD><a target='_blank' href=" . $row[6] ." <td>Click Here</td></a>";
					

					$LOCATION = $_SERVER['PHP_SELF']; $LOCATION = $LOCATION . "?pagenr=$pagenr&mode=E&RNo=$count";
					$ButtonID = "E" . $count; $CnclBtnID = "CNCL" .$count;
					if(isset($_GET['mode']) && $_GET['mode'] == 'E')
					{
						$LOCATION1 = $_SERVER['PHP_SELF']; $LOCATION1 = $LOCATION1 . "?pagenr=$pagenr&mode=&RNo=$count";
						if(isset($_GET['RNo']) && $count == $_GET['RNo'])
							echo "<td" . $edit_col . " align=\"center\"><input name=$ButtonID id=$ButtonID type=\"button\" value=\"Update\" onClick=\"javascript:UgetRecordInfo(" . $pkey . ", " . $num_fields . ", " . $count . ");\" /><br><input name=$CnclBtnID id=$CnclBtnID type=\"button\" value=\"Cancel \" onClick=\"javascript:window.location='" . $LOCATION1 . "'\" /></td>";
						else
							echo "<td" . $edit_col . " align=\"center\"><input name=$ButtonID id=$ButtonID type=\"button\" value=\"Edit\" onClick=\"javascript:window.location='" . $LOCATION . "'\" /></td>";
					}
					else
					{
						echo "<td" . $edit_col . " align=\"center\"><input name=$ButtonID id=$ButtonID type=\"button\" value=\"Edit\" onClick=\"javascript:window.location='" . $LOCATION . "'\" /></td>";

						$LOCATION = $_SERVER['PHP_SELF']; $LOCATION = $LOCATION . "?pagenr=$pagenr&mode=D&RNo=$count";
						$ButtonID = "D" . $count;
						echo "<td" . $del_col . " align=\"center\"><input name=$ButtonID id=$ButtonID type=\"button\" value=\"Archive\" onClick=\"javascript:DgetRecordInfo(" . $pkey . ", " . $num_fields . ", " . $count . ");\" /></td>";

						$LOCATION = $_SERVER['PHP_SELF']; $LOCATION = $LOCATION . "?pagenr=$pagenr&mode=D&RNo=$count";
						$ButtonID = "D" . $count;
						echo "<td" . $del_col . " align=\"center\"><input name=$ButtonID id=$ButtonID type=\"button\" value=\"OK\" onClick=\"javascript:DgetRecordInfo(" . $pkey . ", " . $num_fields . ", " . $count . ");\" /></td>";
					}
					echo "</tr>";
				}

				$count++;
				if($count > $max)
				{
					if($footer_row_visible != 0)
					{
						echo "<tr>";
						echo "<td" . $check_col . " align=\"center\"></td>";
						for($j = 0; $j < $num_fields; $j++)
                                		{
							$footer = "foot" . $j;
							if($j == 1 or $j == 2 or $j == 3 or $j == 4)  // column numbers those should not display the footer content.
								echo "<td align=\"center\"> </td>";
							else
								echo "<td align=\"center\">" . $footer . "</td>";
                                		}
						echo "<td" . $img_col . " align=\"center\"></td>";
						echo "<td" . $edit_col . " align=\"center\"></td>";
						echo "<td" . $del_col . " align=\"center\"></td>";
						echo "<td" . $copy_col . " align=\"center\"></td>";
						echo "</tr>";
					}
					break;
				}
			}
			// ==================================================
			if($count <= $max)
			{
				if($footer_row_visible != 0)
				{
					echo "<tr>";
					echo "<td" . $check_col . " align=\"center\"></td>";
					for($j = 0; $j < $num_fields; $j++)
                               		{
						$footer = "foot" . $j;
						if($j == 1 or $j == 2 or $j == 3 or $j == 4)  // column numbers those should not display the footer content.
							echo "<td align=\"center\"> </td>";
						else
							echo "<td align=\"center\">" . $footer . "</td>";
                               		}
					echo "<td" . $img_col . " align=\"center\"></td>";
					echo "<td" . $edit_col . " align=\"center\"></td>";
					echo "<td" . $del_col . " align=\"center\"></td>";
					echo "<td" . $copy_col . " align=\"center\"></td>";
					echo "</tr>";
				}
			}
			// ==================================================
			$second_prev = $pagenr - 2;
			$first_prev = $pagenr - 1;
			$current = $pagenr;
			$first = $pagenr + 1;
			$second = $pagenr + 2;

			echo "<tr>";
			echo "<td" . $check_col . "></td>";

			echo "<td colspan=$num_fields align=\"right\">";
			if($second_prev >= 1)
			{
				if($second_prev > 1)	echo "... ";
				echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$second_prev>" . $second_prev . "</a>, ";
			}
			if($first_prev >= 1)
				echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$first_prev>" . $first_prev . "</a>, ";

			if($current == $num_pages)
				echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$current style=\"color:Green\">" . $current . "</a>";
			else
				echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$current style=\"color:Green\">" . $current . "</a>, ";

			if($first <= $num_pages)
			{
				if($first == $num_pages)
					echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$first>" . $first . "</a>";
				else
					echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$first>" . $first . "</a>, ";
			}
			if($second <= $num_pages)
			{
        			if($second == $num_pages)
					echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$second>" . $second . "</a>";
				else
					echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$second>" . $second . "</a>, ";
				if($second < $num_pages)	echo "...";
			}
			echo "</td>";

			echo "<td". $img_col . "></td>";
			echo "<td" . $edit_col . "></td>";
			echo "<td". $del_col . "></td>";
			echo "<td" . $copy_col . "></td>";

			echo "</tr>";

			echo "<tr>";
			echo "<td" . $check_col . "></td>";

			echo "<td colspan=$num_fields align=\"right\">";
			if($pagenr > 1)
			{
				echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=1>" . "First" . "</a>";
				echo " ";
			}
			if($pagenr < $num_pages)
				echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$num_pages>" . "Last" . "</a>";

			echo "     ";

			if($first_prev >= 1)
				echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$first_prev>" . "<< Prev" . "</a>";

			if($first <= $num_pages)
			{
				echo " ";
				echo "<a href=$_SERVER[SCRIPT_NAME]?pagenr=$first>" . "Next >>" . "</a>";
			}
			echo "</td>";

			echo "<td" . $img_col . "></td>";
			echo "<td" . $edit_col . "></td>";
			echo "<td" . $del_col . "></td>";
			echo "<td" . $copy_col . "></td>";

			echo "</tr>";

			echo "</table>";
			echo "<br><input id='txtValueCollect' name='txtValueCollect' type='hidden' />";
			echo "</form>";
			//return ReturnValue::SUCCESS;
		}
		catch(Exception $exp)
		{
			echo $exp;
			//$GLOBALS["LH"]->GenerateLog("UIBase", "display_result", "Error: Table drawing error!\n" . $exp, LoggingPriority::Priority6);
			//return ReturnValue::FAILURE;
		}
	}
?>

Recommended Answers

All 5 Replies

Member Avatar for diafol

With which bit do you need help?
Is this your script?

I need dynamic search string for this code.like combo box

With which bit do you need help?
Is this your script?

I need to use dynamic search string.like combo box

Is this your code? And do you mean like a javascript thing as you type is searches? Bring back results as you type, I'm confused by what you want?

Use this one for this
<form name="testform" action=aaaa.php>
<select name="websites" size="1">
<option selected ="">Select a Customer</option>
<option value="GG">GCL</option>
<option value="aa">XLA</option>
<option value="cc">PAC</option>
<option value="ccc">CNE</option>
<option value="index_mo.php">Mobitek1</option>
</select>
<input type="button" value="Get it!"></form>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.