Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/56143-select-all-in-drop-down-list/
Share on other sites

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

 

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>";
		}
	}
	?>

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

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.  ;D

 

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.  :P 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>";
		}
	}

 

 

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.