Copy link to clipboard
Copied
hi,
i have in one form 2 text field 'inf_city' and 'cou_country' and one "check boxes" field with 7 differents choises (each named differently 'type_inf1, 'type_inf2'...) with the possibility of checking more than one...
In the next page, after the validation of this form, i need to use the result of the form using $_GET[’type_inf1']....
my request is this horrible thing....
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$inftype1_InfSelect = "-1";
if (isset($_GET['type_inf1'])) {
$inftype1_InfSelect = $_GET['type_inf1'];
}
$inftype3_InfSelect = "-1";
if (isset($_GET['type_inf3'])) {
$inftype3_InfSelect = $_GET['type_inf3'];
}
$inftype4_InfSelect = "-1";
if (isset($_GET['type_inf4'])) {
$inftype4_InfSelect = $_GET['type_inf4'];
}
$inftype5_InfSelect = "-1";
if (isset($_GET['type_inf5'])) {
$inftype5_InfSelect = $_GET['type_inf5'];
}
$inftype6_InfSelect = "-1";
if (isset($_GET['type_inf6'])) {
$inftype6_InfSelect = $_GET['type_inf6'];
}
$inftype7_InfSelect = "-1";
if (isset($_GET['type_inf7'])) {
$inftype7_InfSelect = $_GET['type_inf7'];
}
$coucountry_InfSelect = "-1";
if (isset($_GET['cou_country'])) {
$coucountry_InfSelect = $_GET['cou_country'];
}
$infcity_InfSelect = "-1";
if (isset($_GET['inf_city'])) {
$infcity_InfSelect = $_GET['inf_city'];
}
$inftype2_InfSelect = "-1";
if (isset($_GET['type_inf2'])) {
$inftype2_InfSelect = $_GET['type_inf2'];
}
mysql_select_db($database_conrestn, $conrestn);
$query_InfSelect = sprintf("SELECT * FROM infrastructures WHERE infrastructures.inf_type = %s OR infrastructures.inf_type = %s OR infrastructures.inf_type = %s OR infrastructures.inf_type = %s OR infrastructures.inf_type = %s OR infrastructures.inf_type = %s infrastructures.inf_type = %s AND infrastructures.inf_idcountry = %s AND infrastructures.inf_city = %s", GetSQLValueString($inftype1_InfSelect, "text"),GetSQLValueString($inftype2_InfSelect, "text"),GetSQLValueString($inftype3_InfSelect, "text"),GetSQLValueString($inftype4_InfSelect, "text"),GetSQLValueString($inftype5_InfSelect, "text"),GetSQLValueString($inftype6_InfSelect, "text"),GetSQLValueString($inftype7_InfSelect, "text"),GetSQLValueString($coucountry_InfSelect, "text"),GetSQLValueString($infcity_InfSelect, "text"));
$InfSelect = mysql_query($query_InfSelect, $conrestn) or die(mysql_error());
$row_InfSelect = mysql_fetch_assoc($InfSelect);
$totalRows_InfSelect = mysql_num_rows($InfSelect);
?>
any possibility of doing easyer?
Cheers
Tim
Copy link to clipboard
Copied
About the check boxes whereby u allow many selection can me made by user, it will be easier if u store them in array, using the implode() function and you can retrieve back all the data using explode() function. You can look at this thread HERE
Copy link to clipboard
Copied
>it will be easier if u store them in array, using the implode() function and you can retrieve back all the data using explode() function.
It really depends on the data and how it is being used, but in general it's a bad idea to store arrays in a database column. If you are simply storing user preferences it's ok, but if the data is something that will be queried you should not store it in an array.
Copy link to clipboard
Copied
i dont need to store those data, i use this form, just to know what the user want to search from the database.
if he wants only 'Hotel', or 'Pub' or other... or maybe 'Hotel' and 'Pub' and....
In the next page the serveur has to compare the selected infrastructures, one or many, and display the related informations about all those infrastructures.
Copy link to clipboard
Copied
Ya, exactly.. It's all depend on what kind of data u may use as an array. Okay, I think I understand it now. Try to do this.
<input name="infrastructure[]" type="checkbox" value="what_the_value_is" />
This will allow user to select what criteria they want to get from database. Then
$infrastructure = $_POST['infrastructure'];
foreach ($infrastructure as $select) {
$query = "THIS THE DATABASE QUERY where 'infrastructure' = $select";
$getData = mysql_query($query) or die(mysql_error());
}
You can view one same problem HERE
Copy link to clipboard
Copied
Depending on your situation you could use SPRY multiple select non-destructive filter
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more