_confused_ Posted June 19, 2007 Share Posted June 19, 2007 hi! i would like to include the option ALL in my drop down list but i'm not quite sure how to do it. pls advise. thanks!! <form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']?>"> <? $query="SELECT kid,ktitle FROM kursuslist order by ktitle"; $result = mysql_query ($query); echo "<select name=progtitle value=''>kid</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt if($id==$nt[kid]) { //echo "<option value=$nt[kid]>$nt[ktitle]</option>"; echo "<option value=$nt[kid] selected=\"selected\">$nt[ktitle]</option>"; } else { echo "<option value=$nt[kid]>$nt[ktitle]</option>"; } /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box</p> ?> <input name="courseEva" type="submit" id="courseEva" value="Hantar Borang"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/56143-select-all-in-drop-down-list/ Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 the all option will have the data inside the drp menu right??? then you should concatenate the value of all the drp menu and place it in all value but to concatenate put a separator for each value like $vau.=$vaule."|"; or any thing you like as long as its unique then to retieve those use explode() or $v[]=$vaule; then get the value of the array Quote Link to comment https://forums.phpfreaks.com/topic/56143-select-all-in-drop-down-list/#findComment-277320 Share on other sites More sharing options...
_confused_ Posted June 19, 2007 Author Share Posted June 19, 2007 hi teng84, thanks for your response. i'm not quite sure what you meant but let me rephrase my question. the system that i'm trying to develop is an evaluation system whereby i can count the ratings (1-5) according to the questions. below is the code i use to grab total of ratings for question no.1 (b1) for one subject (kid). the value of kid is obtained through my drop down list. i intend to calculate all ratings regardless of the course. my current drop down list uses a loop to grab all data. where should i include the option ALL so that i can query my table without filtering kid? <? for ($i=1; $i<=5; $i++){ $query = "SELECT COUNT(bid) FROM boranglist where b1=$i AND kid=$id"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "<td>". $row['COUNT(bid)'] ."</td>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56143-select-all-in-drop-down-list/#findComment-277384 Share on other sites More sharing options...
cooldude832 Posted June 19, 2007 Share Posted June 19, 2007 in that while loop make a $all and make it like its own mini flat file database. $all .= $nt[kid]; $all .= ","; //Delimiter add that in the loop then after the loop echo out a last option with value=$all and then you can deal with it in process Quote Link to comment https://forums.phpfreaks.com/topic/56143-select-all-in-drop-down-list/#findComment-277388 Share on other sites More sharing options...
cooldude832 Posted June 19, 2007 Share Posted June 19, 2007 i retrack my statement because it was said already guess i should read a bit more than the first post Quote Link to comment https://forums.phpfreaks.com/topic/56143-select-all-in-drop-down-list/#findComment-277390 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 i dont understand it that clear but try doing it this way i think its better <? $query = "SELECT COUNT(bid) FROM boranglist where IN ( list all values inthe loop) AND kid=$id"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)) { echo "<td>". $row['COUNT(bid)'] ."</td>"; } ?> then try to comment if im taking you the wrong way Quote Link to comment https://forums.phpfreaks.com/topic/56143-select-all-in-drop-down-list/#findComment-277396 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 opps error change this thing $query = "SELECT COUNT(bid) FROM boranglist where b1 IN (1,2,3,4,5) AND kid=$id"; i forgot the b1 or $query = "SELECT COUNT(bid) FROM boranglist where b1 <=5 AND kid=$id"; Quote Link to comment https://forums.phpfreaks.com/topic/56143-select-all-in-drop-down-list/#findComment-277398 Share on other sites More sharing options...
_confused_ Posted June 19, 2007 Author Share Posted June 19, 2007 hi thr, thanks for the responses.teng84, i've tried your last suggestion but it doesn't work. it will only display the first column of my table. i've modified a few parts of my code. this is my drop down list. <form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']?>"> <? $id = $_POST["progtitle"]; $query="SELECT kid,ktitle FROM kursuslist order by ktitle"; $result = mysql_query ($query); echo "<select name=progtitle value=''>kid</option>"; // printing the list box select command?> <option value="All" <? if (isset($_POST['progtitle'])) {if ($_POST['progtitle']== 'All') {echo "selected";}} ?> >All</option> <? while($nt=mysql_fetch_array($result)){//Array or records stored in $nt if($id==$nt[kid]) { echo "<option value=$nt[kid] selected=\"selected\">$nt[ktitle]</option>"; } else { echo "<option value=$nt[kid]>$nt[ktitle]</option>"; } /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box</p> ?> <input name="courseEva" type="submit" id="courseEva" value="Hantar Borang"> </form> and i can count all my input using the following code... if ($id == "All"){ for ($i=1; $i<=5; $i++){ $query = "SELECT COUNT(bid) FROM boranglist where b2=$i"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "<td>". $row['COUNT(bid)'] ."</td>"; } } } else { for ($i=1; $i<=5; $i++){ $query = "SELECT COUNT(bid) FROM boranglist where b2=$i AND kid=$id"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "<td>". $row['COUNT(bid)'] ."</td>"; } }} it looks kind of messy to me so i'm wondering if i can simplify it by changing it to the code below but it doesn't work. it is possible for us to concatenate a sql statement? for ($i=1; $i<=5; $i++){ if ($id == "All"){ $query = "SELECT COUNT(bid) FROM boranglist where b1=$i"; } else { $query = $query . " AND kid=$id"; } $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "<td>". $row['COUNT(bid)'] ."</td>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/56143-select-all-in-drop-down-list/#findComment-277445 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.