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