Automatic displayfrom select option

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ms.Jemi
Forum Newbie
Posts: 6
Joined: Thu Mar 03, 2011 1:50 am

Automatic displayfrom select option

Post by ms.Jemi »

hi guyz...
Need help!....please...
Here's the problem...
I want to automatically dispaly the table from database when I select from the select option.
Here's my code with a button to display the table...I wat to automatically dispaly without the submit button..I really nid help...please....

Code: Select all

<form name="formState" method="post" action="<?=$_SERVER['PHP_SELF']?>">
College<select name="college">
		<option>Select</option>     
		<option value="CAS">CAS</option> 
		<option value="COA">COA</option> 
		<option value="CBE">CBE</option>
                <option value="CCS">CCS</option> 
		<option value="CED">CED</option> 
		<option value="CEA">CEA</option>
                <option value="CON">CON</option> 
		<option value="STHM">STHM</option> 
		
		
	</select>
        <input type="submit" name="subcol" value="View">
        </form>
 
<?php
if(isset($_POST['subcol'])){
		$colg=$_POST['college'];
		echo $colg;
include("serverConnect.php");
$tempQuery3="Select fldeleccode from tblelections where fldcomid='$comid'";
$resultTemp3 = mysql_query($tempQuery3) or die('Error: '.mysql_error ());
$row4 = mysql_fetch_array($resultTemp3);
$eleccode = $row4['fldeleccode'];
$tempQuery1 = "Select s.fldidnumber,concat( s.fldfname, ' ' ,s.fldmname, '. ' ,s.fldlname ) as fullname,concat(g.fldcourses, ' - ' ,s.fldyear)as cyear from tblcount t,tblstudent s,tblcolleges g,tblelections e where e.fldcomid='$comid' and e.fldeleccode=t.fldeleccode and t.fldidnumber=s.fldidnumber and s.fldcourse=g.fldcourses and g.fldcollegename in (Select fldcollegename from tblcolleges where fldcollegename='$colg')";

$resultTemp1 = mysql_query($tempQuery1) or die('Error: '.mysql_error ());
$num_rows = mysql_num_rows($resultTemp1);

if($num_rows==0)
{
		echo '<br>';
		echo "No student voted in this college!";
}
else{
echo'<table border="1">';
echo '<tr>';

echo '<th>ID Number</th>';
echo '<th>Name</th>';
echo '<th>Course & Yr</th>';
echo '</tr>';



while ($row = mysql_fetch_array($resultTemp1)){
        echo "<tr>";  
 echo "<td>" .$row['fldidnumber']. "</td>";
 echo "<td>" .$row['fullname']. "</td>";
 echo "<td>" .$row['cyear']. "</td>";
 
    
    
 echo "</tr>";
}
echo "</table>";
}
}


        ?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Automatic displayfrom select option

Post by social_experiment »

You should look into AJAX for this :)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply