Jump to content

Auto search with out press of submit button required.


brosskgm

Recommended Posts

I have a template written for me on another project that searches a MySQL database.

 

I'm moving this template to work with a database that only have 10 records in it and instead of having a search option

 

I would just like it to automatically display the database when the page opens. Is this possible?

 

The php page in close to 200 lines. This is the line of the code that has the search option. If you need more I can post it.

 

Thanks

Bob

 

 


<div id="search">
            <form action="parts.php" method="GET">
            Search: <input type="text" value="'.htmlentities($_GET['s']).'" name="s"/> <input type="submit" value="Search!"/>
           </form>
</div>

 

Link to comment
Share on other sites

I didn't write this, it was made for me to lookup parts and costs.

 


<?php
require_once "config.php";
require_once "recaptcha-php-1.11/recaptchalib.php";
global $captchaPublicKey;
Class Template {
public $ResultArray, $numRows = 0;
private $tmpCurr;
public function SimpleGenerate() {
	echo $this->tmpCurr;
}
public function Generate() {
	$captcha = new CaptchaKeys();
?>
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
		<html>
			<head>
				<LINK REL="StyleSheet" HREF="style.css" TYPE="text/css">
				<LINK REL="StyleSheet" HREF="thickbox.css" TYPE="text/css">
				<script type="text/javascript" src="jquery-1.6.4.min.js"></script>
				<script type="text/javascript" src="thickbox-compressed.js"></script>
				<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js?legacy"></script>

				<script language="javascript">

				function removeItem (ItemId) {
					$('#removeImg-'+ItemId).attr("src","img/loader.gif");
					$.get("deleteCart.php",{id:ItemId},function(result) {
						$('#'+ItemId).html(" ");
						$("#totalPrice").html(result);
					});
				}
				function updateItem (ItemId) {
					$("#loading-"+ItemId).html('<img src="img/loader.gif"/>');
					$.get("updateQuantity.php",{id:ItemId,q:$("#quantity-"+ItemId).val()},function(result){
						$("#total-"+ItemId).html(result);
						$("#loading-"+ItemId).html(" ");
						$("#totalPriceLoading").html('<img src="img/loader.gif"/>');
						$.get("totalPrice.php",{},function(result){
							$("#totalPrice").html(result);
							$("#totalPriceLoading").html(' ');
						});
					});
				}
				function updateInfo () {
					$("#loading-info").html('<img src="img/loader.gif"/> Updating...');
					$.get("updateInfo.php",{email:$("#mail").val(),name:$("#name").val(),address:$("#address").val(),city:$("#city").val(),state:$("#state").val(),zip:$("#zip").val(),phone:$("#phone").val()},function(result){
						if (result == "Mail Error") {
							$("#error-info").html('* Please enter a valid mail address');
						}
						if (result == "Mail Success")
							$("#error-info").html('');
						$("#loading-info").html('');
					});
				}
				function Finish () {
					$("#mainloading").html('<img src="img/loader.gif"/>');
					$.post("Finish.php",{recaptcha_challenge_field: Recaptcha.get_challenge(),recaptcha_response_field: Recaptcha.get_response()},function (result) {
						if (result == "Error") {
							$("#mainloading").html('<b>Please Enter Correct Code</b>');
							Recaptcha.reload();
						}
						else {

							$("#main").html(result);
						}
					});
				}
				function FinishNoVal () {
					$("#mainloading").html('<img src="img/loader.gif"/>');
					$.post("Finish.php",{},function (result) {
						$("#main").html(result);
						Recaptcha.create("<?=$captcha->getPublic()?>","Captcha",{theme: "white", callback: Recaptcha.focus_response_field});

					});
				}
				</script>
			</head>
			<body>
				<?=$this->tmpCurr?>
			</body>
		</html>
	<?php


}
public function SearchPage() {

$this->tmpCurr = '
	<div id="search">
				<form action="index.php" method="GET">
					Search: <input type="text" value="'.htmlentities($_GET['s']).'" name="s"/> <input type="submit" value="Search!"/>
				</form>
			</div>
			<br/>';


	if ($this->numRows == 0) {
		$this->tmpCurr .=  "No result";
	}
	elseif ($this->numRows > 0) {
		$this->tmpCurr .= '
			<div id="table_container">
				<div id="table_row">
					<div id="table_cell" class="header">Part #</div>
					<div id="table_cell" class="header">Dealer Cost</div>
					<div id="table_cell" class="header">Markup</div>
					<div id="table_cell" class="header">Retail Cost</div>
					<div id="table_cell" class="header">UOM Type</div>
					<div id="table_cell" class="header">Page#</div>
					<div id="table_cell" class="header">Description</div>
					<div id="table_cell" class="header">Add</div>
				</div>';

		$markup = new Markup();
		for ($i = 0; $i < $this->numRows; $i++) {
			$this->tmpCurr .= '
						<div id="table_row">
							<div id="table_cell" class="cell">'.$this->ResultArray[$i]['part_num'].'</div>
							<div id="table_cell" class="cell">'.number_format(round($this->ResultArray[$i]["dealer"], 2), 2).'</div>
							<div id="table_cell" class="cell">'.number_format(round($markup->Calc($this->ResultArray[$i]["dealer"]) , 2), 2).'</div>
							<div id="table_cell" class="cell">'.number_format(round($this->ResultArray[$i]["retail"], 2), 2).'</div>
							<div id="table_cell" class="cell">'.$this->ResultArray[$i]['uom'].'</div>
							<div id="table_cell" class="cell">'.$this->ResultArray[$i]['page'].'</div>
							<div id="table_cell" class="cell">'.$this->ResultArray[$i]['product_desc'].'</div>
							<div id="table_cell" class="cell"><a class="thickbox" href="addCart.php?id='.$this->ResultArray[$i]["id"].'&height=480">Add to cart</a></div>
						</div>';


		} // end for
		$this->tmpCurr .= '</div>';	
	} //end No Result else
}
public function ListItems ($list) {
	$this->tmpCurr = '<div id="main"><div id="listtable_container"><div class="table_row"><div id="table_cell">Item #</div><div id="table_cell">Description</div><div id="table_cell">Quantity</div><div id="table_cell">Markup</div><div id="table_cell">Total</div><div id="table_cell">Remove</div></div>';
	$ItemsArray = $list->ListItems();
	if ($ItemsArray) { 
		$markup = new Markup();
		foreach ($ItemsArray as $key=>$Item) {
			$this->tmpCurr .= '<div id="'.$Item->id.'" class="table_row"><div id="table_cell">'.$Item->partnum.'</div><div id="table_cell">'.$Item->description.'</div><div id="table_cell"><input type="text" onChange="updateItem(\''.$Item->id.'\');" style="width:25px" id="quantity-'.$Item->id.'" value="'.$Item->quantity.'"/><span id="loading-'.$Item->id.'"></span></div><div id="table_cell">'.number_format(round($markup->Calc($Item->price),2),2).'</div><div id="table_cell"><span id="total-'.$Item->id.'">'.number_format(round($markup->Calc($Item->price),2)*$Item->quantity,2).'</span></div><div id="table_cell"><a href="javascript:removeItem(\''.$Item->id.'\')"><img border="0" id="removeImg-'.$Item->id.'" src="img/delete.gif"/></a></div></div>';
		}
	}
	$this->tmpCurr .= '</div>';
	$this->tmpCurr .= '<div id="dtotalPrice"><span id="totalPriceLoading"></span> Total Price: <span id="totalPrice">'.number_format($list->totalPrice(),2).'</span></div>';
	$this->tmpCurr .= '<div class="leftSide" id="listtable_container">' .
			'<div class="table_row"><div id="table_cell">Email:</div> <div id="table_cell"><input value="'.$list->getEmail().'" onChange="updateInfo();" type="text" id="mail" /> </div></div>' .
			'<div class="table_row"><div id="table_cell">Name:</div> <div id="table_cell"><input value="'.$list->getName().'" onChange="updateInfo();" type="text" id="name" /></div></div>' .
			'<div class="table_row"><div id="table_cell">Address:</div> <div id="table_cell"><input value="'.$list->getAddress().'" onChange="updateInfo();" type="text" id="address" /></div></div>' .
			'<div class="table_row"><div id="table_cell">City:</div> <div id="table_cell"><input value="'.$list->getCity().'" onChange="updateInfo();" type="text" id="city" /></div></div>' .
			'<div class="table_row"><div id="table_cell">State:</div> <div id="table_cell"><input value="'.$list->getState().'" onChange="updateInfo();" type="text" id="state" /></div></div>' .
			'<div class="table_row"><div id="table_cell">ZipCode:</div> <div id="table_cell"><input value="'.$list->getZip().'" onChange="updateInfo();" type="text" id="zip" /></div></div>' .
			'<div class="table_row"><div id="table_cell">Phone:</div> <div id="table_cell"><input value="'.$list->getPhone().'" onChange="updateInfo();" type="text" id="phone" /></div></div>' .


			'</div>' .
			'<span id="loading-info"></span><br/><span id="error-info"></span>';

	$this->tmpCurr .= '<div id="continue"><input onClick="tb_remove();" style="height:30px;padding:5px" type="button" value="Continue"></div> <div id="finish"><input style="height:30px;padding:5px;" type="button" OnClick="FinishNoVal();" value="Finish"/></div><div id="continue"><input type="button" value="Update Cart" style="height:30px;padding:5px"/></div>' .
			'</div>';
}
public function captchaForm () {

	?>

	Please enter the code:<br/>
	<form method="post" action="javascript:Finish()">
		<span id="Captcha"></span>
		<input type="submit" value="Submit"/> <span id="mainloading"></span>
	</form>
	<?php
}
public function emailOutput($list) {
	$Items = $list->ListItems();
	$html = '<table width="100%" border="0"><tr><td>Item #</td><td>Description</td><td>Quantity</td><td>Markup</td><td>Total</td></tr>';
	$markup = new Markup();
	foreach ($Items as $Item) {
		$html .= '<tr><td>'. $Item->partnum .'</td><td>' . $Item->description . '</td><td>' . $Item->quantity . '</td><td>' . number_format(round($markup->Calc($Item->price),2),2) . '</td><td>'.$Item->totalPrice.'</td></tr>';
	}
	$html .= '</table><p align="right">Total Price: <b>' . number_format($list->totalPrice(), 2) . '</b></p>' .
			'<p align="left">' .
				'<table border="0">' .
					'<tr><td>Email:</td><td><b>' . $list->getEmail() . '</b></td></tr>' .
					'<tr><td>Name:</td><td><b>' . $list->getName() . '</b></td></tr>' .
					'<tr><td>Address:</td><td><b>' . $list->getAddress() . '</b></td></tr>' .
					'<tr><td>City:</td><td><b>' . $list->getCity() . '</b></td></tr>' .
					'<tr><td>State:</td><td><b>' . $list->getState() . '</b></td></tr>' .
					'<tr><td>ZipCode:</td><td><b>' . $list->getZip() . '</b></td></tr>' .
					'<tr><td>Phone:</td><td><b>' . $list->getPhone() . '</b></td></tr>' .
				'</table>' .
			'</p>';
	return $html;
}

}
?>


 

You'll have to adapt the PHP file to just display all records. Without the code it's hard to do.

Link to comment
Share on other sites

I almost forgot,

 

This is the part that calls it.

 


<?php
require_once "template.php";
require_once "Search.php";
require_once "Cookie.php";
$Cookie = new Cookie();
$Search = new Search();
$ResultArray = $Search->getResult();
$template = new Template();
$template->ResultArray = $ResultArray;
$template->numRows = $Search->getNumRows();
$template->SearchPage();
$template->Generate();
unset($template);
unset($Search);
?>

 

You'll have to adapt the PHP file to just display all records. Without the code it's hard to do.

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.