Making Advanced Search in Dreamweaver
oicram Sep 9, 2007 6:17 AMI have a database where users need to put data with homeless
dogs.
In that "Insert Page" the user put the Height of the dog in centimeters. (i.e. 80).
Now, in the "Search Dog Page" I want them to search by "Medium" "Big" "Small" where "Medium" "Big" "Small" corresponds a interval of values (always the same).
How can I accomplish this?
Can I use:
SELECT height BETWEEN '0' AND '30' AS smallsize
FROM blabla
HAVING smallsize LIKE somesqlvariable
and this somesqlvariable correspond to $_POST['dropdownsize']
But how can we put the other sizes?
OR,
If I try to do this in the application side:
I will need an IF instruction like this:
if ($_POST["tamanho"] == "pequeno") {
$varintervalo = "alt_cm_an < 30";
} else if ($_POST["tamanho"] == "medio") {
$varintervalo = "alt_cm_an >= 30 AND size < 40";
} else if ($_POST["tamanho"] == "grande") {
$varintervalo = "alt_cm_an >= 40";
}
and this:
SELECT * FROM dogs WHERE $intervalo
And this:
Combo Box
<select id="tamanho" name="Tamanho" >
<option> pequeno </option>
<option> medio</option>
<option> grande </option>
</select>
But if I put this in dreamweaver, I get exclamation marks ! in my Server Behaviors panel or simple I don't see my Recordset !!
And I have no clue where to put the IF statement in the code without getting errors from dreamweaver.
So far here is my first TRY:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::BEGIN::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::
<?php
(...)
$vartipo_rs_procurar_animais = "-1";
if (isset($_POST['tipo'])) {
$vartipo_rs_procurar_animais = $_POST['tipo'];
}
$varintervalo_rs_procurar_animais = "-1";
if (isset($_POST['tamanho'])) {
$varintervalo_rs_procurar_animais = $_POST['tamanho'];
}
$varestado_rs_procurar_animais = "-1";
if (isset($_POST['estado'])) {
$varestado_rs_procurar_animais = $_POST['estado'];
}
$varsexo_rs_procurar_animais = "-1";
if (isset($_POST['sexo'])) {
$varsexo_rs_procurar_animais = $_POST['sexo'];
}
mysql_select_db($database_conn_db_cantinho, $conn_db_cantinho);
if ($_POST["tamanho"] == "pequeno") {
$varintervalo_rs_procurar_animais = "alt_cm_an < 30";
} else if ($_POST["tamanho"] == "medio") {
$varintervalo_rs_procurar_animais = "alt_cm_an >= 30 AND size < 40";
} else if ($_POST["tamanho"] == "grande") {
$varintervalo_rs_procurar_animais = "alt_cm_an >= 40";
}
$query_rs_procurar_animais = sprintf("SELECT CURDATE(), (YEAR(CURDATE())-YEAR(data_nasc_an)) - (RIGHT(CURDATE(),5)<RIGHT(data_nasc_an,5)) AS idade, id_an, tipo_an, nome_pt_an, sexo_pt_an, est_animal, alt_cm_an FROM animal WHERE %s AND tipo_an LIKE %s AND sexo_pt_an LIKE %s AND est_animal LIKE %s", GetSQLValueString($varintervalo_rs_procurar_animais, "text"),GetSQLValueString($vartipo_rs_procurar_animais, "text"),GetSQLValueString($varsexo_rs_procurar_animais, "text"),GetSQLValueString($varestado_rs_procurar_animais, "text"));
$query_limit_rs_procurar_animais = sprintf("%s LIMIT %d, %d", $query_rs_procurar_animais,
(...)
?>
<body>
<form id="procurar_animal" name="procurar_animal" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label>Nome:
<input type="text" name="Nome" id="Nome" />
Tipo:
<select name="tipo" id="tipo">
<option value="cao" <?php if($_POST['tipo'] == "cao") echo "selected"; ?>>Cão</option>
<option value="gato" <?php if($_POST['tipo'] == "gato") echo "selected"; ?>>Gato</option>
<option value="outro" <?php if($_POST['tipo'] == "outro") echo "selected"; ?>>Outro</option>
</select>
</label>
<label>Estado:
<select name="estado" id="estado">
<option value="%" <?php if($_POST['estado'] == "%") echo "selected"; ?> >Qualquer</option>
<option value="nao adoptado" <?php if($_POST['estado'] == "nao adoptado") echo "selected"; ?> >Não Adoptado</option>
<option value="adoptado" <?php if($_POST['estado'] == "adoptado") echo "selected"; ?> >Adoptado</option>
<option value="reservado" <?php if($_POST['estado'] == "reservado") echo "selected"; ?> >Reservado</option>
<option value="desaparecido" <?php if($_POST['estado'] == "desaparecido") echo "selected"; ?> >Desaparecido</option>
<option value="falecido" <?php if($_POST['estado'] == "falecido") echo "selected"; ?> >Falecido</option>
</select>
Sexo:
<select name="sexo" id="sexo">
<option value="%" <?php if($_POST['%'] == "%") echo "selected"; ?> >Qualquer</option>
<option value="masculino" <?php if($_POST['sexo'] == "masculino") echo "selected"; ?> >Masculino</option>
<option value="feminino" <?php if($_POST['sexo'] == "feminino") echo "selected"; ?> > Feminino</option>
</select>
</label>
<label>Idade:
<select name="idade" id="idade">
<option>Qualquer</option>
<option>Bebé</option>
<option>Jovem</option>
<option>Adulto</option>
<option>Velhote</option>
</select>
</label>
<label>Tamanho:
<select name="tamanho" id="tamanho">
<option value="%">Qualquer</option>
<option value="varintervalo_rs_procurar_animais < 30">Pequeno</option>
<option value="varintervalo_rs_procurar_animais >= 30 AND varintervalo_rs_procurar_animais < 40">Médio</option>
<option value="varintervalo_rs_procurar_animais > 40">Grande</option>
</select>
<br />
<br />
</label>
<label></label>
<input type="submit" name="pesquisa" id="pesquisa" value="Pesquisar" />
</form>
<table border="1">
<tr>
<td>ID</td>
<td>Tipo</td>
<td>Nome</td>
<td>Sexo</td>
<td>Idade</td>
<td>Tamanho</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rs_procurar_animais['id_an']; ?></td>
<td><?php echo $row_rs_procurar_animais['tipo_an']; ?></td>
<td><?php echo $row_rs_procurar_animais['nome_pt_an']; ?></td>
<td><?php echo $row_rs_procurar_animais['sexo_pt_an']; ?></td>
</tr>
<?php } while ($row_rs_procurar_animais = mysql_fetch_assoc($rs_procurar_animais)); ?>
</table>
<?php } // Show if recordset not empty ?>
</body>
</html>
<?php
mysql_free_result($rs_procurar_animais);
?>
::::::::::::::::::::::::::::::::::::::::::::::::::::::::END::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::
Hope you can help me with this.
In that "Insert Page" the user put the Height of the dog in centimeters. (i.e. 80).
Now, in the "Search Dog Page" I want them to search by "Medium" "Big" "Small" where "Medium" "Big" "Small" corresponds a interval of values (always the same).
How can I accomplish this?
Can I use:
SELECT height BETWEEN '0' AND '30' AS smallsize
FROM blabla
HAVING smallsize LIKE somesqlvariable
and this somesqlvariable correspond to $_POST['dropdownsize']
But how can we put the other sizes?
OR,
If I try to do this in the application side:
I will need an IF instruction like this:
if ($_POST["tamanho"] == "pequeno") {
$varintervalo = "alt_cm_an < 30";
} else if ($_POST["tamanho"] == "medio") {
$varintervalo = "alt_cm_an >= 30 AND size < 40";
} else if ($_POST["tamanho"] == "grande") {
$varintervalo = "alt_cm_an >= 40";
}
and this:
SELECT * FROM dogs WHERE $intervalo
And this:
Combo Box
<select id="tamanho" name="Tamanho" >
<option> pequeno </option>
<option> medio</option>
<option> grande </option>
</select>
But if I put this in dreamweaver, I get exclamation marks ! in my Server Behaviors panel or simple I don't see my Recordset !!
And I have no clue where to put the IF statement in the code without getting errors from dreamweaver.
So far here is my first TRY:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::BEGIN::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::
<?php
(...)
$vartipo_rs_procurar_animais = "-1";
if (isset($_POST['tipo'])) {
$vartipo_rs_procurar_animais = $_POST['tipo'];
}
$varintervalo_rs_procurar_animais = "-1";
if (isset($_POST['tamanho'])) {
$varintervalo_rs_procurar_animais = $_POST['tamanho'];
}
$varestado_rs_procurar_animais = "-1";
if (isset($_POST['estado'])) {
$varestado_rs_procurar_animais = $_POST['estado'];
}
$varsexo_rs_procurar_animais = "-1";
if (isset($_POST['sexo'])) {
$varsexo_rs_procurar_animais = $_POST['sexo'];
}
mysql_select_db($database_conn_db_cantinho, $conn_db_cantinho);
if ($_POST["tamanho"] == "pequeno") {
$varintervalo_rs_procurar_animais = "alt_cm_an < 30";
} else if ($_POST["tamanho"] == "medio") {
$varintervalo_rs_procurar_animais = "alt_cm_an >= 30 AND size < 40";
} else if ($_POST["tamanho"] == "grande") {
$varintervalo_rs_procurar_animais = "alt_cm_an >= 40";
}
$query_rs_procurar_animais = sprintf("SELECT CURDATE(), (YEAR(CURDATE())-YEAR(data_nasc_an)) - (RIGHT(CURDATE(),5)<RIGHT(data_nasc_an,5)) AS idade, id_an, tipo_an, nome_pt_an, sexo_pt_an, est_animal, alt_cm_an FROM animal WHERE %s AND tipo_an LIKE %s AND sexo_pt_an LIKE %s AND est_animal LIKE %s", GetSQLValueString($varintervalo_rs_procurar_animais, "text"),GetSQLValueString($vartipo_rs_procurar_animais, "text"),GetSQLValueString($varsexo_rs_procurar_animais, "text"),GetSQLValueString($varestado_rs_procurar_animais, "text"));
$query_limit_rs_procurar_animais = sprintf("%s LIMIT %d, %d", $query_rs_procurar_animais,
(...)
?>
<body>
<form id="procurar_animal" name="procurar_animal" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label>Nome:
<input type="text" name="Nome" id="Nome" />
Tipo:
<select name="tipo" id="tipo">
<option value="cao" <?php if($_POST['tipo'] == "cao") echo "selected"; ?>>Cão</option>
<option value="gato" <?php if($_POST['tipo'] == "gato") echo "selected"; ?>>Gato</option>
<option value="outro" <?php if($_POST['tipo'] == "outro") echo "selected"; ?>>Outro</option>
</select>
</label>
<label>Estado:
<select name="estado" id="estado">
<option value="%" <?php if($_POST['estado'] == "%") echo "selected"; ?> >Qualquer</option>
<option value="nao adoptado" <?php if($_POST['estado'] == "nao adoptado") echo "selected"; ?> >Não Adoptado</option>
<option value="adoptado" <?php if($_POST['estado'] == "adoptado") echo "selected"; ?> >Adoptado</option>
<option value="reservado" <?php if($_POST['estado'] == "reservado") echo "selected"; ?> >Reservado</option>
<option value="desaparecido" <?php if($_POST['estado'] == "desaparecido") echo "selected"; ?> >Desaparecido</option>
<option value="falecido" <?php if($_POST['estado'] == "falecido") echo "selected"; ?> >Falecido</option>
</select>
Sexo:
<select name="sexo" id="sexo">
<option value="%" <?php if($_POST['%'] == "%") echo "selected"; ?> >Qualquer</option>
<option value="masculino" <?php if($_POST['sexo'] == "masculino") echo "selected"; ?> >Masculino</option>
<option value="feminino" <?php if($_POST['sexo'] == "feminino") echo "selected"; ?> > Feminino</option>
</select>
</label>
<label>Idade:
<select name="idade" id="idade">
<option>Qualquer</option>
<option>Bebé</option>
<option>Jovem</option>
<option>Adulto</option>
<option>Velhote</option>
</select>
</label>
<label>Tamanho:
<select name="tamanho" id="tamanho">
<option value="%">Qualquer</option>
<option value="varintervalo_rs_procurar_animais < 30">Pequeno</option>
<option value="varintervalo_rs_procurar_animais >= 30 AND varintervalo_rs_procurar_animais < 40">Médio</option>
<option value="varintervalo_rs_procurar_animais > 40">Grande</option>
</select>
<br />
<br />
</label>
<label></label>
<input type="submit" name="pesquisa" id="pesquisa" value="Pesquisar" />
</form>
<table border="1">
<tr>
<td>ID</td>
<td>Tipo</td>
<td>Nome</td>
<td>Sexo</td>
<td>Idade</td>
<td>Tamanho</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rs_procurar_animais['id_an']; ?></td>
<td><?php echo $row_rs_procurar_animais['tipo_an']; ?></td>
<td><?php echo $row_rs_procurar_animais['nome_pt_an']; ?></td>
<td><?php echo $row_rs_procurar_animais['sexo_pt_an']; ?></td>
</tr>
<?php } while ($row_rs_procurar_animais = mysql_fetch_assoc($rs_procurar_animais)); ?>
</table>
<?php } // Show if recordset not empty ?>
</body>
</html>
<?php
mysql_free_result($rs_procurar_animais);
?>
::::::::::::::::::::::::::::::::::::::::::::::::::::::::END::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::
Hope you can help me with this.

