Me han corroborado que tu forma seria la correcta saint. Pero no entiendo muy bien el foreach y en php.net tampoco lo veo muy claro. He echo esto de prueba.
Pero aparte de que no lo entiendo muy bien, no me sale. (espero que puedas ayudarme).
Código PHP:
<?php
if(isset($_POST['submit-filtrar'])){
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
$d = $_POST['d'];
// arrays de los datos recogidos en el form
$datos_form = array(
"a" => array(
"post" => $_POST['a'],
"cond" => "opcion_a='A'"
),
"b" => array(
"post" => $_POST['b'],
"cond" => "opcion_b='B'"
),
"c" => array(
"post" => $_POST['c'],
"cond" => "opcion_c='C'"
),
"d" => array(
"post" => $_POST['d'],
"cond" => "opcion_d='D'"
)
);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
<style type="text/css">
<!--
.Estilo1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #006699;
}
.Estilo2 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #006699; font-weight: bold; }
.Estilo3 {font-family: Arial, Helvetica, sans-serif; font-size: 9px; color: #006699; }
-->
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" rowspan="2" align="center" valign="middle"> </td>
<td height="350" align="left" valign="bottom">
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="Estilo2">RESULTADOS DEL FILTRADO:</td>
</tr>
<tr>
<td height="10" valign="top"></td>
</tr>
<tr>
<td valign="top" bgcolor="#9FE0FF" class="Estilo3" style="padding:8px;">
<?php
foreach($datos_form as $condicion=>$post){
echo "$condicion=>$post AND ";
}
?>
</td>
</tr>
<tr>
<td height="100" valign="top"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="200" align="left" valign="top" class="Estilo1">
<form action="" method="post" name="form-filtrar">
Selecciona para filtrar:
<br />
<hr style="margin:8px 0px 5px 0px;" color="#006699" width="80%" />
<br />
<select name="a" id="a">
<option value="NULL">Selecciona</option>
<option value="A01">A01</option>
<option value="A02">A02</option>
<option value="A03">A03</option>
</select>
<select name="b" id="b">
<option value="NULL">Selecciona</option>
<option value="B01">B01</option>
<option value="B02">B02</option>
<option value="B03">B03</option>
</select>
<select name="c" id="c">
<option value="NULL">Selecciona</option>
<option value="C01">C01</option>
<option value="C02">C02</option>
<option value="C03">C03</option>
</select>
<select name="d" id="d">
<option value="NULL">Selecciona</option>
<option value="D01">D01</option>
<option value="D02">D02</option>
<option value="D03">D03</option>
</select>
<br />
<br />
<input name="submit-filtrar" type="submit" id="submit-filtrar" value="Filtrar" />
</form>
</td>
</tr>
</table>
</body>
</html>