ddean Posted October 1, 2007 Share Posted October 1, 2007 Hi everybody, I'm rather new to PHP, so forgive my ignorance. I'm trying to make movie catalog. I made a drop down list containing movie genres, and if one selects one genre it would filter database and show chosen genre. It all works perfectly. except I want add one more option to drop down list called /all/ and I want it when selected from drop down list to show all records. And I dont know how to do it. please give some idea. here's the code: <form id="form1" name="form1" method="post" action=""> <label>Prikaži samo : <select name="tbl_filmovi_zanr" id="tbl_filmovi_zanr"> <option value="all" selected="selected">ALL</option> <option value="akcija">akcije</option> <option value="animirani">crtiće</option> <option value="avantura">avanturističke</option> <option value="bajka">bajke</option> <option value="borilacki">borilacke</option> <option value="dokumentarni">dokumentarce</option> <option value="drama">drame</option> <option value="ex yu">ex yu</option> <option value="horor">horore</option> <option value="JBOND">James bondove</option> <option value=" komedija">komedije</option> <option value=" manga">manga crtiće</option> <option value=" muzicki">muzicke</option> <option value=" ratni">ratne</option> <option value=" romansa">romanse</option> <option value=" scifi">scifi</option> <option value=" spektakl">spektakle</option> <option value=" western">westerne</option> <option value=" zatvorski">zatvorske</option> </select> <input type="submit" name="button" id="button" value="Submit" /> </label> </form> <table> <tr bgcolor="#CCCCCC"> <?php echo "<th class='top' width='4%'><a href='DVDkat.php?sort=tbl_filmovi_rb&order=$orderin'>Rb</a></td>"; echo "<th class='top' width='35%'><a href='DVDkat.php?sort=tbl_filmovi_imefilma&order=$orderin'>NASLOV</a></td>"; echo "<th class='top' width='7%'><a href='DVDkat.php?sort=tbl_filmovi_regija&order=$orderin'>REGIJA</a></td>"; echo "<th class='top' width='3%'><a href='DVDkat.php?sort=tbl_filmovi_medij&order=$orderin'>MEDIJ</a></td>"; echo "<th class='top' width='10%'><a href='DVDkat.php?sort=tbl_filmovi_zanr&order=$orderin'>ZANR</a></td>"; echo "<th class='top' width='7%'><a href='DVDkat.php?sort=tbl_filmovi_lokacija&order=$orderin'>LOKACIJA</a></td>"; echo "<th class='top' width='10%'><a href='DVDkat.php?sort=tbl_filmovi_rezija&order=$orderin'>REZIJA</a></td>"; echo "<th class='top' width='24%'><a href='DVDkat.php?sort=tbl_filmovi_glumi&order=$orderin'>GLUMI</a></td>"; ?> <?php $upitzanr = $_POST['tbl_filmovi_zanr']; if (isset($_POST['tbl_filmovi_zanr'])) { mysql_select_db($db, $link); $query = "SELECT * FROM tbl_filmovi WHERE tbl_filmovi_zanr = '$upitzanr' ORDER BY tbl_filmovi_imefilma ASC";} else if ($_POST['tbl_filmovi_zanr'] = 'all') { $query = "SELECT * FROM tbl_filmovi ORDER BY tbl_filmovi_rb DESC";} else {$query = "SELECT * FROM tbl_filmovi ORDER BY tbl_filmovi_rb DESC";} $result = mysql_query($query) or die("Query failed: " . mysql_error()); while ($row=mysql_fetch_array($result)) { $id = $row['tbl_filmovi_rb']; $loc = $row['tbl_filmovi_lokacija']; $reg = $row['tbl_filmovi_regija']; $name = $row['tbl_filmovi_imefilma']; $zanr = $row['tbl_filmovi_zanr']; $med = $row['tbl_filmovi_medij']; $rez = $row['tbl_filmovi_rezija']; $glum = $row['tbl_filmovi_glumi']; } mysql_select_db($db, $link); $result = mysql_query($query, $link); if(mysql_num_rows($result)) { $rank = 1; while($row = mysql_fetch_row($result)) { print("</tr><tr>"); if($color == "#D8DBFE") { $color = "#a9bac3"; } else { $color = "#D8DBFE"; } print("<td width=\"4%\" bgcolor=\"$color\">$row[0]</td>"); print("<td width=\"35%\" bgcolor=\"$color\"><strong><a href='DVDedit.php?id=$row[0]'>$row[1]</a></strong></td>"); print("<td width=\"7%\" bgcolor=\"$color\">$row[2]</td>"); print("<td width=\"3%\" bgcolor=\"$color\">$row[3]</td>"); print("<td width=\"10%\" bgcolor=\"$color\">$row[4]</td>"); print("<td width=\"7%\" bgcolor=\"$color\">$row[5]</td>"); print("<td width=\"10%\" bgcolor=\"$color\">$row[6]</td>"); print("<td width=\"24%\" bgcolor=\"$color\">$row[7]</td>"); $rank++; } } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/71333-solved-problem-with-select-if/ Share on other sites More sharing options...
shocker-z Posted October 1, 2007 Share Posted October 1, 2007 Try this mate <form id="form1" name="form1" method="post" action=""> <label>Prikaži samo : <select name="tbl_filmovi_zanr" id="tbl_filmovi_zanr"> <option value="all" selected="selected">ALL</option> <option value="akcija">akcije</option> <option value="animirani">crtiće</option> <option value="avantura">avanturističke</option> <option value="bajka">bajke</option> <option value="borilacki">borilacke</option> <option value="dokumentarni">dokumentarce</option> <option value="drama">drame</option> <option value="ex yu">ex yu</option> <option value="horor">horore</option> <option value="JBOND">James bondove</option> <option value=" komedija">komedije</option> <option value=" manga">manga crtiće</option> <option value=" muzicki">muzicke</option> <option value=" ratni">ratne</option> <option value=" romansa">romanse</option> <option value=" scifi">scifi</option> <option value=" spektakl">spektakle</option> <option value=" western">westerne</option> <option value=" zatvorski">zatvorske</option> </select> <input type="submit" name="button" id="button" value="Submit" /> </label> </form> <table> <tr bgcolor="#CCCCCC"> <?php echo "<th class='top' width='4%'><a href='DVDkat.php?sort=tbl_filmovi_rb&order=$orderin'>Rb[/url]</td>"; echo "<th class='top' width='35%'><a href='DVDkat.php?sort=tbl_filmovi_imefilma&order=$orderin'>NASLOV[/url]</td>"; echo "<th class='top' width='7%'><a href='DVDkat.php?sort=tbl_filmovi_regija&order=$orderin'>REGIJA[/url]</td>"; echo "<th class='top' width='3%'><a href='DVDkat.php?sort=tbl_filmovi_medij&order=$orderin'>MEDIJ[/url]</td>"; echo "<th class='top' width='10%'><a href='DVDkat.php?sort=tbl_filmovi_zanr&order=$orderin'>ZANR[/url]</td>"; echo "<th class='top' width='7%'><a href='DVDkat.php?sort=tbl_filmovi_lokacija&order=$orderin'>LOKACIJA[/url]</td>"; echo "<th class='top' width='10%'><a href='DVDkat.php?sort=tbl_filmovi_rezija&order=$orderin'>REZIJA[/url]</td>"; echo "<th class='top' width='24%'><a href='DVDkat.php?sort=tbl_filmovi_glumi&order=$orderin'>GLUMI[/url]</td>"; ?> <?php $upitzanr = $_POST['tbl_filmovi_zanr']; if ($_POST['tbl_filmovi_zanr'] == 'all') { mysql_select_db($db, $link); $query = "SELECT * FROM tbl_filmovi WHERE tbl_filmovi_zanr = '$upitzanr' ORDER BY tbl_filmovi_imefilma ASC";} elseif (isset($_POST['tbl_filmovi_zanr'])) { $query = "SELECT * FROM tbl_filmovi ORDER BY tbl_filmovi_rb DESC"; } $result = mysql_query($query) or die("Query failed: " . mysql_error()); while ($row=mysql_fetch_array($result)) { $id = $row['tbl_filmovi_rb']; $loc = $row['tbl_filmovi_lokacija']; $reg = $row['tbl_filmovi_regija']; $name = $row['tbl_filmovi_imefilma']; $zanr = $row['tbl_filmovi_zanr']; $med = $row['tbl_filmovi_medij']; $rez = $row['tbl_filmovi_rezija']; $glum = $row['tbl_filmovi_glumi']; } mysql_select_db($db, $link); $result = mysql_query($query, $link); if(mysql_num_rows($result)) { $rank = 1; while($row = mysql_fetch_row($result)) { print("</tr><tr>"); if($color == "#D8DBFE") { $color = "#a9bac3"; } else { $color = "#D8DBFE"; } print("<td width=\"4%\" bgcolor=\"$color\">$row[0]</td>"); print("<td width=\"35%\" bgcolor=\"$color\"><strong><a href='DVDedit.php?id=$row[0]'>$row[1][/url]</strong></td>"); print("<td width=\"7%\" bgcolor=\"$color\">$row[2]</td>"); print("<td width=\"3%\" bgcolor=\"$color\">$row[3]</td>"); print("<td width=\"10%\" bgcolor=\"$color\">$row[4]</td>"); print("<td width=\"7%\" bgcolor=\"$color\">$row[5]</td>"); print("<td width=\"10%\" bgcolor=\"$color\">$row[6]</td>"); print("<td width=\"24%\" bgcolor=\"$color\">$row[7]</td>"); $rank++; } } ?> </table> just noticed 2 things you were doing a check to see if an option was selected then saying if not selected and it equals all then do somthing but if it wasn't sdelected then it wont = all also you used = instead of == in your statement. See if that works Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/71333-solved-problem-with-select-if/#findComment-358972 Share on other sites More sharing options...
ddean Posted October 1, 2007 Author Share Posted October 1, 2007 Thank you very much, it works now! Quote Link to comment https://forums.phpfreaks.com/topic/71333-solved-problem-with-select-if/#findComment-358977 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.