Writing a website in php and html and need basic search functions

This is for a class at the local university. I’ve been coding and trying to implement things here and there, but I’m lost on what to write for a search function.

http://is462project.x10host.com/dealership/list.php is the website, and what i would like to do is make these results sortable by name, year, mileage, price ascending and descending. It seems trivial, but I don’t think I’m putting the right code in the right place. Thank you!

In order to help you, you’ll need to show us the code that you’re having problems with. If you have no code then you need to go to hire-a-programmer section in order to get help.

Strider, thank you! I haven’t had a chance to get on here, but I believe this is what the code entails. I have taken this from various sources, written in some things, and then edited others. I just need a drop down box to sort the information accordingly on the website. Line 188 or somewhere in there are comments that I think is where i need to write the code, but anything I’ve written hasn’t worked. Thank you in advance![php]<?php
function DoEvents($that) {
global $_CONF, $_PAGE, $_TSM , $base;

$jpp = (int)$that->vars->data["ipp"];

$_models = $that->db->QFetchRowArray("SELECT * FROM {$that->tables[make]}");
if (is_array($_models)) {
	foreach ($_models as $key => $var) {
		$models[$var["make_id"]] = $var["make_name"];
	}		
}


switch ($_GET["sub"]) {
	
	case "error":
		return $that->templates["error"]->output;
	break;
	
	case "paycalc":
	return $that->templates["paycalc"]->output;
	break;
	
	case "staff":
	return $that->templates["staff"]->output;
	break;
	
	case "diag":
	return $that->templates["diag"]->output;
	break;
	
	
	case "search":
		$data = $_GET;
		
		if (is_array($_models)) {
			foreach ($_models as $key => $val) {
				if ($val["make_parent"] == 0) {
					$make[$val["make_id"]] = $val["make_name"];

					$js .= "models[{$val[make_id]}] = new Array();\n";
					$i = 1;
					$js .= "models[{$val[make_id]}][" . $i++ ."] = new Option(\"[ select ]\" , \"\"); \n";
					foreach ($_models as $k => $v) {
						if ($v["make_parent"] == $val["make_id"]) {
							$js .= "models[{$val[make_id]}][" . $i++ ."] = new Option(\"{$v[make_name]}\" , \"{$v[make_id]}\"); \n";
						}							
					}						
				}					
			}
		}

		$data["make"] = $base->html->FormSelect("make" , $make, $that->templates["search"] , "Select" , "" , "" , array("ONCHANGE" => "Model(this.value)"));
		$data["script"] = $js;
		//Need to set to sort by alphabetical order on search page

		$data["model"] = $base->html->FormSelect("model" , $schools, $that->templates["search"] , "Select" , "");
		

		$that->templates["search"]->blocks["Search"]->Replace($data , false);
		$form = $that->templates["search"]->blocks["Search"]->EmptyVars();


		//check if there was tried a search
		if ($_GET["model"] || $_GET["pf"] || $_GET["pt"] || $_GET["yf"] || $_GET["yt"] || $_GET["make"]) {
			//ok, this was a search funcion here

			$query[] =  " car_make= " . (int) $_GET["make"] . " " . ( $_GET["model"] ? " AND car_model = '{$_GET[model]}' " : "" ) ;
			
			if ($_GET["pf"] || $_GET["pt"])
				$query[] = " (car_price >= " . (int) $_GET["pf"] . "" . ($_GET["pt"] ? " AND car_price <= "  . (int) $_GET["pt"] . "" : "")  . ") ";
				//getting variables here and there.

			if ($_GET["yf"] || $_GET["yt"])
				$query[] = " (car_year >= " . (int) $_GET["yf"] . "" . ($_GET["yt"] ? " AND car_year <= "  . (int) $_GET["yt"] . "" : "")  . ") ";
			
			if (is_array($query)) {
				$page = $_GET["page"] ? ($_GET["page"] - 1) * $jpp : 0;
				$cars = $that->db->QFetchRowArray("SELECT * FROM {$that->tables[cars]} WHERE" . implode(" AND " , $query) . " ORDER BY car_year asc LIMIT $page,$jpp");
				//you can switch these manually, but if we can switch this with a dropdown, that would be great. 
				$count = $that->db->RowCount($that->tables["cars"] , "WHERE " . implode(" AND " , $query) . " ");
			} else
				return $form;
		} else 
			return $form;
	break;

	case "details":
		$car = $that->db->QFetchArray("SELECT * FROM {$that->tables[cars]} WHERE car_id='{$_GET[id]}'");
		if (is_array($car)) {
			$car["car_make"] = $models[$car["car_make"]];
			$car["car_model"] = $models[$car["car_model"]];
			$car["car_price"] = number_format($car["car_price"] , 2);
			$car["referer"] = $_SERVER["HTTP_REFERER"] ? $_SERVER["HTTP_REFERER"]  : "list.php";
			$car["name"] = $car["address"] = $car["msg"] = $car["error"] = "";
			$car["id"] = $car["car_id"];

			if ($car["car_tn_image"]) {
				$car["image"] = $that->templates["details"]->blocks["Image"]->Replace(array(
																									"SOURCE" => "upload/car_" . $car["car_id"] . ".jpg",
																									"SOURCE2" => $car["car_image"] ? "href=\"upload/bcar_" . $car["car_id"] . ".jpg\"" : "",
																									"TARGET" => $car["car_image"] ? " target=\"_new\" " : ""
				
																								));				
			} else {
				$car["image"] = "";
			}			

			$car["contact_form"] = $that->templates["details"]->blocks["Contact"]->Replace($car);

			//read the images if are any to read
			$images = $that->db->QFetchRowArray("SELECT * FROM {$that->tables[photos]} WHERE car='{$_GET[id]}'");
			if (is_array($images)) {
				foreach ($images as $key => $image) {
					$images["$key"]["source"] = $image["image"] ? "upload/photo_" . $image["id"] . ".jpg" : "upload/tn_photo_" . $image["id"] . ".jpg";
					$images["$key"]["source1"] = $image["tn"] ? "upload/tn_photo_" . $image["id"] . ".jpg" : "upload/photo_" . $image["id"] . ".jpg";
				}
				
				$images = $base->html->Table($that->templates["details"],"List",$images);			
			} else 
				$images = "";
			

			return $that->templates["details"]->blocks["Main"]->Replace($car) .  $images;	
		} else {
			header("Location: error.php");
			exit;
		}					
	break;
	
	case "insurance":
	return $that->templates["insurance"]->output;
	break;
	
	case "appt":
	return $that->templates["appt"]->output;
	break;

	case "send":

	if ($_SERVER["REQUEST_METHOD"] == "POST") {
			if ($_POST["name"] && $_POST["address"] && $_POST["msg"]) {

			$car = $that->db->QFetchArray("SELECT * FROM {$that->tables[cars]} WHERE car_id='{$_POST[id]}'");
			$car["car_make"] = $models[$car["car_make"]];
			$car["car_model"] = $models[$car["car_model"]];
			$car["car_price"] = number_format($car["car_price"] , 2);

				$msg = $_POST["msg"] . "\n" . 
						"\n\nPerson Details:\n"	.
						"	Name: {$_POST[name]}\n" . 
						"	Email: {$_POST[address]}\n" . 
						"	IP & Hostname: {$_SERVER[REMOTE_ADDR]} {$_SERVER[REMOTE_HOST]} \n" . 							
						"\n\nCar Details:\n" .
						"	Make & Model: {$car[car_make]} {$car[car_model]} \n" . 
						"	Year: {$car[car_year]} \n" . 
						"	Price: \${$car[car_price]} \n" . 
						"	Mileage: {$car[car_mileage]} \n" . 
						"	Tracking Number: {$car[car_track]} \n" .
						($that->vars->data["mail_link"] ? "	Origin Link: http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER["SCRIPT_NAME"]) . "/details.php?id={$_POST[id]}" : "");

				$headers  = "MIME-Version: 1.0\n"; 
				$headers .= "Content-type: text/plain\n"; 
				$headers .= "From: $_POST[name] <{$_POST[address]}>\n"; 
				$headers .= "Reply-to: $_POST[name] <{$_POST[address]}>\n"; 
				//Man, I hope this code works. 
				
				@mail( $that->vars->data["mail_address"] , $that->vars->data["mail_title"], $msg, $headers);

				return $that->templates["details"]->blocks["Thanks"]->Replace($_POST);


			} else {
				$_POST["error"] = "Please fill in all fields!";
				$_POST["car_id"] = $_POST["id"];
				return $that->templates["details"]->blocks["Contact"]->Replace($_POST);
			}				
			
		} else {
			header("Location: error.php");
			exit;
		}
		
	break;

	default:
	//I KNOW I PUT THE SORT FUNCTION IN HERE SOMEWHERE. I DON'T KNOW WHERE!
		$page = $_GET["page"] ? ($_GET["page"] - 1) * $jpp : 0;
		//sort by car year. can change to whatever if needed. 
		$cars = $that->db->QFetchRowArray("SELECT * FROM {$that->tables[cars]} ORDER BY car_year asc LIMIT $page , $jpp ");
		$count = $that->db->RowCount($that->tables["cars"] , "");
	break;		
}

$alternance = 1;


if (is_array($cars)) {

	foreach ($cars as $key => $val) {

		$cars[$key]["car_make"] = $models[$val["car_make"]];
		$cars[$key]["car_model"] = $models[$val["car_model"]];
		$cars[$key]["car_price"] = number_format($val["car_price"] , 2);

		//also add the alternance template
		$cars[$key]["alternance"] = $that->templates["list"]->blocks["Alternance" . $alternance]->output;

		if ($val["car_tn_image"]) {
			$cars[$key]["tn_image"] = $that->templates["list"]->blocks["Image"]->Replace(array(
																								"SOURCE" => "upload/car_" . $val["car_id"] . ".jpg",
																								"SOURCE2" => $val["car_image"] ? "href=\"upload/bcar_" . $val["car_id"] . ".jpg\"" : "",
																								"TARGET" => $val["car_image"] ? " target=\"_new\" " : ""
			
																							));				
		} else {
			$cars[$key]["tn_image"] = "";
		}			
		//switch
		$alternance = !$alternance;
	}		
}

if (is_array($_GET)) {
	foreach ($_GET as $key => $val) {
		if ($key != "page") 
			$out[] = "$key=" . urlencode($val);
	}
	$extra = is_array($out) ? implode("&" , $out) . "&" : "";
}


return $form . $base->html->Table($that->templates["list"],"List",$cars,true,$count,$jpp,$_GET["page"],$that->templates["paging"],array(
																																	"base" => in_array($_GET["sub"] , array ("search")) ? $_GET["sub"] . ".php" : "list.php" ,
																																	"extra" => $extra,
																																	"what" => $_GET["what"] ? "what=" . $_GET["what"] . "&" : ""
																																));

}
?>[/php]

Anything? Simple drop down sort menu for the database query results?

Sponsor our Newsletter | Privacy Policy | Terms of Service