Tema: Buscador???
Ver Mensaje Individual
  #4 (permalink)  
Antiguo 15/10/2004, 10:43
YDIABLOY
 
Fecha de Ingreso: septiembre-2004
Mensajes: 58
Antigüedad: 19 años, 7 meses
Puntos: 0
este es mi codigo

$pSearch = @$HTTP_GET_VARS["psearch"];
$pSearchType = @$HTTP_GET_VARS["psearchtype"];
if ($pSearch <> "") {
$pSearch = str_replace("'", "\'", $pSearch);
if ($pSearchType <> "") {
while (strpos($pSearch, " ") > 0) {
$pSearch = str_Replace(" ", " ",$pSearch);
}
$arpSearch = explode(" ", trim($pSearch));
foreach ($arpSearch as $kw) {
$b_search .= "(";
$b_search .= "`tumnail` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`flash` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`año` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`marca` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`modelo` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`transmision` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`motor` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`aire` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`direccion` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`vidrios` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`cierre` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`precio` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`extras` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`financiamiento` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`garantia` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`combustible` LIKE '%" . trim($kw) . "%' OR ";
$b_search .= "`tipo` LIKE '%" . trim($kw) . "%' OR ";
if (substr($b_search, -4) == " OR ") {
$b_search = substr($b_search, 0, strlen($b_search)-4);
}
$b_search .= ") " . $pSearchType . " ";
}
} else {
$b_search .= "`tumnail` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`flash` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`año` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`marca` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`modelo` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`transmision` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`motor` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`aire` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`direccion` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`vidrios` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`cierre` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`precio` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`extras` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`financiamiento` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`garantia` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`combustible` LIKE '%" . $pSearch . "%' OR ";
$b_search .= "`tipo` LIKE '%" . $pSearch . "%' OR ";
}
}
if (substr($b_search, -4) == " OR ") {
$b_search = substr($b_search, 0, strlen($b_search)-4);
}
if (substr($b_search, -5) == " AND ") {
$b_search = substr($b_search, 0, strlen($b_search)-5);
}

// build search criteria
if ($a_search <> "") {
$searchwhere = $a_search; //advanced search
} elseIf ($b_search <> "") {
$searchwhere = $b_search; //basic search
}

// save search criteria
if ($searchwhere <> "") {
$HTTP_SESSION_VARS["autos_searchwhere"] = $searchwhere;
$startRec = 1; //reset start record counter (new search)
$HTTP_SESSION_VARS["autos_REC"] = $startRec;
} else {
$searchwhere = @$HTTP_SESSION_VARS["autos_searchwhere"];
}

// get clear search cmd
if (@$HTTP_GET_VARS["cmd"] <> "") {
$cmd = $HTTP_GET_VARS["cmd"];
if (strtoupper($cmd) == "RESET") {
$searchwhere = ""; //reset search criteria
$HTTP_SESSION_VARS["autos_searchwhere"] = $searchwhere;
} elseif (strtoupper($cmd) == "RESETALL") {
$searchwhere = ""; //reset search criteria
$HTTP_SESSION_VARS["autos_searchwhere"] = $searchwhere;
}
$startRec = 1; //reset start record counter (reset command)
$HTTP_SESSION_VARS["autos_REC"] = $startRec;
}

// build dbwhere
if ($masterdetailwhere <> "" ) {
$dbwhere .= "(" . $masterdetailwhere . ") AND ";
}
if ($searchwhere <> "" ) {
$dbwhere .= "(" . $searchwhere . ") AND ";
}
if (strlen($dbwhere) > 5) {
$dbwhere = substr($dbwhere, 0, strlen($dbwhere)-5); // trim rightmost AND
}

// default order
$DefaultOrder = "";
$DefaultOrderType = "";

// default filter
$DefaultFilter = "";

// check for an Order parameter
$OrderBy = "";
if (@$HTTP_GET_VARS["order"] <> "") {
$OrderBy = $HTTP_GET_VARS["order"];

// check if an ASC/DESC toggle is required
if (@$HTTP_SESSION_VARS["autos_OB"] == $OrderBy) {
if (@$HTTP_SESSION_VARS["autos_OT"] == "ASC") {
$HTTP_SESSION_VARS["autos_OT"] = "DESC";
} else {
$HTTP_SESSION_VARS["autos_OT"] = "ASC";
}
} else {
$HTTP_SESSION_VARS["autos_OT"] = "ASC";
}
$HTTP_SESSION_VARS["autos_OB"] = $OrderBy;
$HTTP_SESSION_VARS["autos_REC"] = 1;
} else {
$OrderBy = @$HTTP_SESSION_VARS["autos_OB"];
if ($OrderBy == "") {
$OrderBy = $DefaultOrder;
$HTTP_SESSION_VARS["autos_OB"] = $OrderBy;
$HTTP_SESSION_VARS["autos_OT"] = $DefaultOrderType;
}
}
$conn = mysql_connect(HOST, USER, PASS);
mysql_select_db(DB);

// build SQL
$strsql = "SELECT * FROM `autos`";
if ($DefaultFilter <> "") {
$whereClause .= "(" . $DefaultFilter . ") AND ";
}
if ($dbwhere <> "" ) {
$whereClause .= "(" . $dbwhere . ") AND ";
}
if (substr($whereClause, -5) == " AND ") {
$whereClause = substr($whereClause, 0, strlen($whereClause)-5);
}
if ($whereClause <> "") {
$strsql .= " WHERE " . $whereClause;
}
if ($OrderBy <> "") {
$strsql .= " ORDER BY `" . $OrderBy . "` " . @$HTTP_SESSION_VARS["autos_OT"];
}

//echo $strsql; // comment out this line to view the SQL
$rs = mysql_query($strsql);
$totalRecs = intval(@mysql_num_rows($rs));

// check for a START parameter
if (@$HTTP_GET_VARS["start"] <> "") {
$startRec = $HTTP_GET_VARS["start"];
$HTTP_SESSION_VARS["autos_REC"] = $startRec;
} elseif (@$HTTP_GET_VARS["pageno"] <> "") {
$pageno = $HTTP_GET_VARS["pageno"];
if (is_numeric($pageno)) {
$startRec = ($pageno - 1)*$displayRecs + 1;
if ($startRec <= 0) {
$startRec = 1;
} elseIf ($startRec >= (($totalRecs-1)/$displayRecs)*$displayRecs+1) {
$startRec = (($totalRecs-1)/$displayRecs)*$displayRecs + 1;
}
$HTTP_SESSION_VARS["autos_REC"] = $startRec;
} else {
$startRec = @$HTTP_SESSION_VARS["autos_REC"];
if (!is_numeric($startRec)) {
$startRec = 1; // reset start record counter
$HTTP_SESSION_VARS["autos_REC"] = $startRec;
}
}
} else {
$startRec = @$HTTP_SESSION_VARS["autos_REC"];
if (!is_numeric($startRec)) {
$startRec = 1; // reset start record counter
$HTTP_SESSION_VARS["autos_REC"] = $startRec;
}
}
?>
<?php include ("header.php") ?>
<form action="BUSCAR.php">
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td>
<select name="psearch1" value="<?php echo htmlspecialchars(@$x_tipo); ?>">
<option value="sedan">sedan</option>
<option value="4x4">4x4</option>
</select>
<select name="psearch2" value="<?php echo htmlspecialchars(@$x_marca); ?>">
<option value="BMW">BMW</option>
<option value="MITSUBISHI">MITSUBISHI</option>
</select>
<input type="Submit" name="Submit" value="buscar">
&nbsp;&nbsp;<a href="autoslist.php?cmd=reset">listado completo </span></a> </td>
</tr>
<tr>
<td><a href="autoslist.php?psearch=sedan&Submit=buscar&ps earchtype=">sedan</a> -- <a href="autoslist.php?psearch=4x4&Submit=buscar&psea rchtype=">4x4 </a> -- <a href="autoslist.php?psearch=pickup&Submit=buscar&p searchtype=">pickup</a> -- <a href="autoslist.php?psearch=micro&Submit=buscar&ps earchtype=%20">microbuses</a> -- <a href="autoslist.php?psearch=motocicletas&Submit=bu scar&psearchtype=">motocicletas</a> </td>
</tr>
</table>
</form>
<form method="post">
<table border="0" cellspacing="1" cellpadding="4" bgcolor="#FFFFFF">
<?php

// avoid starting record > total records
if ($startRec > $totalRecs) {
$startRec = $totalRecs;
}

// set the last record to display
$stopRec = $startRec + $displayRecs - 1;
$recCount = $startRec - 1;

// move to the first record
@mysql_data_seek($rs, $recCount);
$recActual = 0;
$contador=0;
?>
<tr bgcolor="<?php echo $bgcolor; ?>"><?
while (($row = @mysql_fetch_array($rs)) && ($recCount < $stopRec)) {
$recCount++;
if ($recCount >= $startRec) {
$recActual++;
$bgcolor = "#FFFFFF"; // row color
if (($recCount % 2) <> 0) { // display alternate color for rows
$bgcolor = "#F5F5F5";
}

// load key for record
$key = @$row["id"];
$x_id = @$row["id"];
$x_tumnail = @$row["tumnail"];
$x_flash = @$row["flash"];
$x_aF1o = @$row["año"];
$x_marca = @$row["marca"];
$x_modelo = @$row["modelo"];
$x_transmision = @$row["transmision"];
$x_motor = @$row["motor"];
$x_aire = @$row["aire"];
$x_direccion = @$row["direccion"];
$x_vidrios = @$row["vidrios"];
$x_cierre = @$row["cierre"];
$x_precio = @$row["precio"];
$x_extras = @$row["extras"];
$x_financiamiento = @$row["financiamiento"];
$x_garantia = @$row["garantia"];
$x_combustible = @$row["combustible"];
$x_tipo = @$row["tipo"];
?>
<td><span class="phpmaker"><a href="<?php echo (@$row["id"] != NULL) ? "autosview.php?key=".urlencode($row["id"]) : "javascript:alert('Invalid Record! Key is null');"; ?>"><img src="<?php echo $x_tumnail; ?>" width="120" height="90" border="0"></a>&nbsp;</td>

<?php
$contador += 1;
if ($contador == "4")
{
echo "</TR><TR>";
$contador = "0";
}

}
}
?></tr>
</table>
</form>
<?php

// close connection
@mysql_free_result($rs);
mysql_close($conn);
?>
<table border="0" cellspacing="0" cellpadding="10"><tr><td>
<?php
if ($totalRecs > 0) {
$rsEof = ($totalRecs < ($startRec + $displayRecs));
$PrevStart = $startRec - $displayRecs;
if ($PrevStart < 1) $PrevStart = 1;
$NextStart = $startRec + $displayRecs;
if ($NextStart > $totalRecs ) $NextStart = $startRec;
$LastStart = intval(($totalRecs-1)/$displayRecs)*$displayRecs+1;
?>
<form>