Jump to content

PHP/mysql 2 dropdown lists filter & display on screen result


icebgg

Recommended Posts

Hello to all.

I'm new here and i am very glad to be a part of this community.

I am new in PHP/mysql but i try to learn as much as i can in php & mysql.

 

And here is the problem:

Into  a php or html page i want to display 2 dropdown list to act as a filter for displaying a table.

I managed to display a table based on option select from first dropdown but i don'y know how to make  or activate the second dropdown list to act as a filter, and when i press "result" to display on the same page the results.

 

Thanks a lot.

Link to comment
Share on other sites

<?php

// Conectare la baza de date

$conn = mysql_connect("localhost","root","asd")

or die("Nu ma pot conecta" . mysql_error());

echo("Conected MySQL" . " | ");

mysql_select_db("p3")       

or die("Nu ma pot conecta" . mysql_error() . "|");

echo ("Conected to Database " . "<br/>");

?>

<?php

include 'pageloadtime.php';

?>

<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' >

    <select name="value">

<option value=""></option>

        <option value="Toate">Toate</option>

        <option value="Optiunea1">Optiunea1</option>

        <option value="Optiunea2">Optiunea2</option>

<option value="Optiunea3">Optiunea3</option>

<option value="Optiunea4">Optiunea4</option>

</select>

<select name="value">

<option value=""></option>

<option value="Pilon1">Pilonul1</option>

<option value="Pilon2">Pilonul2</option>

<option value="Pilon3">Pilonul3</option>

</select>

    <input type='submit' value = 'Trimite!'>

<input type='reset' value = 'Anuleaza!'>

<input type="text" name="text de introdus" size="25">

<input type="submit" name="submit" value="Search">

<input type='reset' value = 'Anuleaza!'>

</form>

 

<?php

if ($_POST['value'] == 'Pilon1')

{

$query5= mysql_query ("SELECT id_csspp,p  FROM reg_id_comp WHERE  p IS NOT NULL ORDER by id_csspp ASC");

echo "<table border='1'>

<tr>

<th>id_csspp</th>

<th>p</th>

</tr>";

while ($row = mysql_fetch_array($query5))

{

echo "<tr>";

echo "<tr>" . $row['id_csspp'] . "</td>";

echo "<tr>" . $row['p'] . "</td>";

echo "</tr>";

}

echo "</table>";

echo "<br/>";

}

elseif ($_POST['value'] == 'Pilon2')

{

$query6= mysql_query ("SELECT id_csspp,p  FROM reg_id_comp WHERE  p IS NOT NULL ORDER by id_csspp ASC");

echo "<table border='1'>

<tr>

<th>id_csspp</th>

<th>p</th>

</tr>";

while ($row = mysql_fetch_array($query6))

{

echo "<tr>";

echo "<tr>" . $row['id_csspp'] . "</td>";

echo "<tr>" . $row['p'] . "</td>";

echo "</tr>";

}

echo "</table>";

echo "<br/>";

}

elseif ($_POST['value'] == 'Pilon3')

{

$query7= mysql_query ("SELECT id_csspp,p  FROM reg_id_comp WHERE  p IS NOT NULL ORDER by id_csspp ASC");

echo "<table border='1'>

<tr>

<th>id_csspp</th>

<th>p</th>

</tr>";

while ($row = mysql_fetch_array($query7))

{

echo "<tr>";

echo "<tr>" . $row['id_csspp'] . "</td>";

echo "<tr>" . $row['p'] . "</td>";

echo "</tr>";

}

echo "</table>";

echo "<br/>";

}

else

echo "<font color='#FF0000'>Nu ai selectat al 2-lea criteriu!!!</font>";

?>

 

<?php

if($_POST['value'] == 'Optiunea1')

{

{

$query = mysql_query("SELECT * FROM reg_id_comp WHERE nr_stop IS NOT NULL");

echo "<table border='1'>

<tr>

<th>id_csspp</th>

<th>nr_stop</th>

</tr>";

}

while ($row = mysql_fetch_array($query))

{

echo "<tr>";

echo "<td>" . $row['id_csspp'] . "</td>";

echo "<td>" . $row['nr_stop'] . "</td>";

echo "</tr>";

}

echo "</table>";

echo "<br/>";

}

elseif($_POST['value'] == 'Optiunea2')

{

{

    $query1 = mysql_query("SELECT * FROM reg_id_comp WHERE date_stop IS NOT NULL");

echo "<table border='1'>

<tr>

<th>id_cssp</th>

<th>date_stop</th>

</tr>";

}

while ($row = mysql_fetch_array($query1))

{

echo  "<tr>";

echo  "<td>" . $row['id_csspp']  . "</td>";

echo  "<td>" . $row['date_stop'] . "</td>";

echo "</tr>";

}

echo "</table>";

echo "<br/>";

}

elseif($_POST['value'] == 'Optiunea3')

{

{

    $query2 = mysql_query("

SELECT

id_csspp,nr_lic,date_lic,comp_name,comp_mnemo,nr_stop,date_stop

FROM

reg_id_comp

WHERE

id_csspp

LIKE

'FP%'

AND

date_stop

IS NOT NULL

AND

p = 2

ORDER BY

comp_mnemo

ASC

");

echo "<table border='1'>

<tr>

<th>id_csspp</th>

<th>nr_lic</th>

<th>date_lic</th>

<th>comp_name</th>

<th>comp_mnemo</th>

<th>nr_stop</th>

<th>date_stop</th>

</tr>";

}

while ($row = mysql_fetch_array($query2))

{

echo  "<tr>";

echo  "<td>" . $row['id_csspp'] . "</td>";

echo  "<td>" . $row['nr_lic'] . "</td>";

echo  "<td>" . $row['date_lic'] . "</td>";

echo  "<td>" . $row['comp_name'] . "</td>";

echo  "<td>" . $row['comp_mnemo'] . "</td>";

echo  "<td>" . $row['nr_stop'] . "</td>";

echo  "<td>" . $row['date_stop'] . "</td>";

echo "</tr>";

}

echo "</table>";

echo "<br/>";

}

elseif($_POST['value'] == 'Toate')

{

{

    $query3 = mysql_query("SELECT * FROM reg_id_comp");

echo "<table border='1'>

<tr>

<th>id_csspp</th>

<th>date_upd</th>

<th>active</th>

<th>url_doc</th>

<th>id_foreign</th>

<th>cc_comp</th>

<th>cui</th>

<th>c_onrc</th>

<th>p</th>

<th>gov_mod</th>

<th>nr_lic</th>

<th>date_lic</th>

<th>nr_stop</th>

<th>date_stop</th>

<th>comp_name</th>

<th>comp_short</th>

<th>comp_mnemo</th>

<th>id_rep</th>

<th>legal_rep</th>

<th>post_addr</th>

<th>post_code</th>

<th>url_comp</th>

<th>email_comp</th>

<th>iban_ron</th>

<th>iban_curr</th>

<th>isin</th>

<th>shr_total</th>

<th>shr_val</th>

<th>shr_curr</th>

<th>info_1</th>

<th>info_2</th>

<th>info_3</th>

<th>info_4</th>

</tr>";

}

while ($row = mysql_fetch_array($query3))

{

echo  "<tr>";

echo  "<td>" . $row['id_csspp'] . "</td>";

echo  "<td>" . $row['date_upd'] . "</td>";

echo  "<td>" . $row['active'] . "</td>";

echo  "<td>" . $row['url_doc'] . "</td>";

echo  "<td>" . $row['id_foreign'] . "</td>";

echo  "<td>" . $row['cc_comp'] . "</td>";

echo  "<td>" . $row['cui'] . "</td>";

echo  "<td>" . $row['c_onrc'] . "</td>";

echo  "<td>" . $row['p'] . "</td>";

echo  "<td>" . $row['gov_mod'] . "</td>";

echo  "<td>" . $row['nr_lic'] . "</td>";

echo  "<td>" . $row['date_lic'] . "</td>";

echo  "<td>" . $row['nr_stop'] . "</td>";

echo  "<td>" . $row['date_stop'] . "</td>";

echo  "<td>" . $row['comp_name'] . "</td>";

echo  "<td>" . $row['comp_short'] . "</td>";

echo  "<td>" . $row['comp_mnemo'] . "</td>";

echo  "<td>" . $row['id_rep'] . "</td>";

echo  "<td>" . $row['legal_rep'] . "</td>";

echo  "<td>" . $row['post_addr'] . "</td>";

echo  "<td>" . $row['post_code'] . "</td>";

echo  "<td>" . $row['url_comp'] . "</td>";

echo  "<td>" . $row['email_comp'] . "</td>";

echo  "<td>" . $row['iban_ron'] . "</td>";

echo  "<td>" . $row['iban_curr'] . "</td>";

echo  "<td>" . $row['isin'] . "</td>";

echo  "<td>" . $row['shr_total'] . "</td>";

echo  "<td>" . $row['shr_val'] . "</td>";

echo  "<td>" . $row['shr_curr'] . "</td>";

echo  "<td>" . $row['info_1'] . "</td>";

echo  "<td>" . $row['info_2'] . "</td>";

echo  "<td>" . $row['info_3'] . "</td>";

echo  "<td>" . $row['info_4'] . "</td>";

echo "</tr>";

}

echo "</table>";

echo "<br/>";

}

elseif($_POST['value'] == 'Optiunea4')

{

{

    $query4 = mysql_query("

SELECT

id_csspp,nr_lic,date_lic,comp_name,comp_mnemo

FROM

reg_id_comp

WHERE

id_csspp

LIKE

'DEP%'

AND

date_stop

IS  NULL

AND

p = 2

ORDER BY

comp_mnemo

ASC

");

echo "<table border='1'>

<tr>

<th>id_csspp</th>

<th>nr_lic</th>

<th>date_lic</th>

<th>comp_name</th>

<th>comp_mnemo</th>

</tr>";

}

while ($row = mysql_fetch_array($query4))

{

echo  "<tr>";

echo  "<td>" . $row['id_csspp'] . "</td>";

echo  "<td>" . $row['nr_lic'] . "</td>";

echo  "<td>" . $row['date_lic'] . "</td>";

echo  "<td>" . $row['comp_name'] . "</td>";

echo  "<td>" . $row['comp_mnemo'] . "</td>";

echo "</tr>";

}

echo "</table>";

echo "<br/>";

}

else

echo "<font color='#FF0000'>Alegeti o optiune!!!</font>";

?>

Link to comment
Share on other sites

please please please :code_php_tags::anim_rules::code_php_tags:

 

You can't name two different elements with the same name if plan on using them individualy.  Also, don't use PHP_SELF, just set the action to "#".  You will need to rename one of your select elements and then build conditional checks against the pair of them.  Look into arrays, for this many checks they would make the most sense.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.