This is a script that search for parameters in a mysql database. Some fields in the db contains data numbers
and the others contains alphabetic data.
The script had to search, by user choice, from a multiple choice form, for numbers or for alphabetical or for numbers and alphabetical data together.
Maybe, IMHO, there's some problems in the string comparison part.
I've a minimal php experience but I'm trying to learn. If someone can and want to help I'll be very grateful.
Ciao.
:rolleyes:
// declare row color
$coloredtable = "2";
// connect to Mysql
$link = mysql_connect ($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
// start PAGERESULT
function pageresult($fil)
{
global $coloredtable;
global $seno; global $vita; global $fianchi; global $altezza; global $taglia; global $scarpe; global $occhi; global $capelli;
$f = implode("",file($fil));
if ($coloredtable == "1") {$coloredtable = "2";} else {$coloredtable = "1";};
$f = str_replace("[>COLOREDTABLE]","$coloredtable",$f);
$f = str_replace("[>SENO<]","$seno",$f); // this is a number field
$f = str_replace("[>VITA<]","$vita",$f); // this is a number field
$f = str_replace("[>FIANCHI<]","$fianchi",$f); // this is a number field
$f = str_replace("[>ALTEZZA<]","$altezza",$f); // this is a number field
$f = str_replace("[>TAGLIA<]","$taglia",$f); // this is a number field
$f = str_replace("[>SCARPE<]","$scarpe",$f); // this is a number field
$f = str_replace("[>OCCHI<]","$occhi",$f); // this is an alphabetic field
$f = str_replace("[>CAPELLI<]","$capelli",$f); // this is an alphabetic field
return $f;
}
// end PAGERESULT
// start query
$result = mysql_query("SELECT * FROM `nuke_xragazze`");
$totalRows_link = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
$seno = $row["seno"];
$vita = $row["vita"];
$fianchi = $row["fianchi"];
$altezza = $row["altezza"];
$taglia = $row["taglia"];
$scarpe = $row["scarpe"];
$occhi = $row["occhi"];
$capelli = $row["capelli"];
// declare numeric string
$senomas = explode("-", $Senoselect);
$vitamas = explode("-", $Vitaselect);
$fianchimas = explode("-", $Fianchiselect);
$altezzamas = explode("-", $Altezzaselect);
$tagliamas = explode("-", $tagliaselect);
$scarpemas = explode("-", $scarpeselect);
// declare alphabetical strings
// $occhiresult = $occhiselect;
// $capelliresult = $capelliselect;
// start numeric string comparison...
if ( (($seno >= $senomas[0]) and ($seno <= $senomas[1]))
AND (($vita >= $vitamas[0]) and ($vita <= $vitamas[1]))
AND (($fianchi >= $fianchimas[0]) and ($fianchi <= $fianchimas[1]))
AND (($altezza >= $altezzamas[0]) and ($altezza <= $altezzamas[1]))
AND (($taglia >= $tagliamas[0]) and ($taglia <= $tagliamas[1]))
AND (($scarpe >= $scarpemas[0]) and ($scarpe <= $scarpemas[1]))
// end numeric string comparison...
// start alphabetical string comparison...
AND (if ($occhiselect == "all") else ($occhiselect == $occhi))
AND $capelliresult == $capelli
// end alphabetical string comparison... but doesn't work!! the search wont work!
)
{
// this echo the results on a template
echo pageresult("search_result.tml");