Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

advanced search

Status
Not open for further replies.

soniasonia

Technical User
Aug 20, 2002
2
AR
I am working on a page where I have to search over three tables. The seach form has the posibility of select:
location: the whole country, state,capital (radio button)
Search by: department, tel, address, manager (dropdown list)
Text: (textbox).
I am having problems with the code. I would like to know where I can get a good example code of this kind. I have alreday looked for it but I coundnt find anything like tthat. I you like I could send you what I made.
Sorry for my English. Any help will be really appreciated.

Sonia.
 
Please send your code in order to help you... I don`t know what is your problem... Someone who has never served other is someone that has never lived...
 
$sql="select * from mytable where"
//assume country=1, state=2, capitol=3
//assume if country is picked, all records are searched
//therefore no need to alter $sql to limit the search
if ($localradiobuttonvalue=2){
$sql=$sql." state = '$state'";
}elseif ($localradiobutton=3){
//$searchby = the dropdown list
//$text = entry in text box...note that tel numbers must
//be stored as text to by picked up
$sql=$sql." and $searchby = '$text'";
}
$result = mysql_query($sql,$conn) or die ("Database not available");

//code to show the results...

hth
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
I send you the code:
CONSULTA2.PHP
<HTML>
<HEAD>
<TITLE> Subsistema de Areas </TITLE>
</HEAD>
<BODY>
<H1> Subsistema de Consultas</H1>
<FORM ACTION=&quot;listaconsulta.php&quot; METHOD=POST>
<p align=&quot;left&quot;>Locación:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Capital<input type=&quot;radio&quot; &quot; value=&quot;capital&quot;checked name=&quot;locacion&quot;>&nbsp;&nbsp;&nbsp;&nbsp;
Interior <input type=&quot;radio&quot; value=&quot;interior&quot; name=&quot;locacion&quot;>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Todo&nbsp; <input type=&quot;radio&quot; value=&quot;todos&quot; name=&quot;locaion&quot;></p>

<p align=&quot;left&quot;>Búsqueda por:&nbsp;&nbsp;&nbsp; <select size=&quot;1&quot; name=&quot;busquedapor&quot;>
<option selected>Area</option>
<option>Agente</option>
<option>Edificio</option>
<option>Telefono</option>
</select></p>

<p align=&quot;left&quot;>Ingresar el texto: <input type=&quot;text&quot; name=&quot;searchtext&quot; size=&quot;20&quot;></p>

<p align=&quot;left&quot;><input type=&quot;submit&quot; value=&quot;Buscar&quot; >
<input type=&quot;reset&quot; value=&quot;Restablecer&quot; >&nbsp;</p>
</FORM>

<P ALIGN=CENTER><A HREF=&quot;admin.html&quot;>Regreso al Inicio</A></P>
</BODY>
</HTML>

LISTACONSULTA.PHP
<HTML>
<HEAD>
<TITLE> Subsistema de Areas </TITLE>
</HEAD>
<BODY>
<H1>Subsistema de Consulta</H1>
<P><A HREF=&quot;consulta2.php&quot;>Nueva Consulta</A></P>
<?php

$dbcnx = @mysql_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;);
mysql_select_db(&quot;miprueba&quot;);

// The basic SELECT statement
$select = &quot;SELECT DISTINCT arid, eid&quot;;
$from = &quot; FROM todos&quot;;
$where = &quot; WHERE arid > 0 OR eid > 0 &quot;;

if (locacion == 'todos') {
$from .= &quot;,edificios&quot;;
$where .= &quot; AND id=eid&quot;;
}

if (locacion == 'capital') {
$from .= &quot;,edificios&quot;;
$where .= &quot; AND id=eid AND sede='capital'&quot;;
}

if (locacion == 'interior') {
$from .= &quot;,edificios&quot;;
$where .= &quot; AND id=eid AND sede <> 'capital'&quot;;
}

if (busquedapor == 'Area') {
$from .= &quot;, areas&quot;;
if (searchtext != &quot;&quot;) {
$where .= &quot; AND id=arid AND descripcion LIKE '%searchtext%'&quot;;
} else {
$where .= &quot; AND id=arid&quot;;
}

if (busquedapor == 'Agente') {
$from .= &quot;, agentes&quot;;
if (searchtext != &quot;&quot;) {
$where .= &quot; AND id=aid AND nombre LIKE '%searchtext%' OR apellido LIKE '%searchtext%&quot;;
} else {
$where .= &quot; AND id=aid&quot;;
}

if (busquedapor == 'Telefono') {
$from .= &quot;, areas&quot;;
if (searchtext != &quot;&quot;) {
$where .= &quot; AND id=arid AND tel1 LIKE '%searchtext%' OR tel2 LIKE '%searchtext%' OR tel3 LIKE '%searchtext%' OR tel4 LIKE '%searchtext%'&quot;;
} else {
$where .= &quot; AND id=arid&quot;;
}

if (busquedapor == 'Edificio') {
$from .= &quot;, edificios&quot;;
if (searchtext != &quot;&quot;) { // Some search text was specified
$where .= &quot; AND id=eid AND domicilio LIKE '%searchtext%'&quot;;
} else {
$where .= &quot; AND id=eid&quot;;
}
?>

<TABLE BORDER=1>
<TR><TH>Area</TH></TR>

<?php
$areas = mysql_query($select . $from . $where);
if (!areas) {
echo(&quot;</TABLE>&quot;);
echo(&quot;<P>Error al traer Areas desde la DB !<BR>&quot;.
&quot;Error: &quot; . mysql_error());
exit();
}

while ($area = mysql_fetch_array($areas)) {
echo(&quot;<TR>\n&quot;);
$id = $area[&quot;id&quot;];
$descripcion = $area[&quot;descripcion&quot;];

}
?>

</TABLE>
</BODY>
</HTML>

db: MIPRUEBA
tables:
AGENTES
ID
NOMBRE
APELLIDO
DNI
PROFESION
SEXO
EMAIL
AREAS
ID
DESCRIPCION
TEL1
TEL2
TEL3
TEL4
AID
EDIFICIOS
ID
DOMICILIO
SEDE
TODOS
ARID
EID


Hope you can help me.
 
Pues yo veo algunos errores de variables mal escritas...checa bien tu código o cuál es tu problema??? que es lo que hace mal???

faltan algunos $...y además cuando le indicas que los valores se tomaron de la forma con algo como $HTTP_POST_VARS
o $GLOBALS

//Variables tomadas de la forma
$nom = $GLOBALS[&quot;nombre&quot;];
$log = $GLOBALS[&quot;login&quot;];
$pas = $GLOBALS[&quot;passwd&quot;];

por ejemplo...
Someone who has never served other is someone that has never lived...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top