Jump to content

Problem with displaying the correct Result


ashrafzia

Recommended Posts

I am getting a value from the table of the field no_of_semester.

suppose the no_of_semester for the programe BCS are 8.

 

Now i have to put the no_of_semester value in a listbox but the no_of_semester will start from 1,2,3.....8, which will be defenetly done with the help of a loop.

 

I have the following logic applied but doesn't seems to work.

 

<?php
include "connection.php";
$prog_name = $_POST['first'];


$sql = "SELECT	programmes.no_of_semesters
	FROM programmes
	WHERE	programmes.programe_name = '$prog_name' ";

$result = mysql_query($sql, $conn) or die (mysql_error());

while ($row = mysql_fetch_array($result)){
	$sem = $row['no_of_semesters'];
}

	$select =  "<select id=\"semester\" name=\"semester\">
		<option value=\"\">--Select--</option>";

for ($i=1;$i<=$sem;$i++)
{
	$add .= "<option value='$sem[$i]'>$sem[$i]</option>";
	echo "$add";	
}
	$select .="</select>";
	echo "$select";

?>

 

Any idea!!

 

 

One problem I notice is $sem is assumed to be an array, which its not. You need.....

 

while ($row = mysql_fetch_array($result)){
  $sem[] = $row['no_of_semesters'];
}

 

Thoough im really not sure why you'd do it that way. What exactly are you trying to do? Sorry, your question is very unclear.

<?php
include "connection.php";

$first = $_POST['first'];
$prog_name =$first;

$sql = "SELECT programmes.no_of_semesters FROM programmes WHERE 
programmes.programe_name = '$prog_name' ";
$result = mysql_query($sql, $conn) or die (mysql_error());


$select="<select id='semester' name='semester'>

while ($sem = mysql_fetch_array($result)){

$select=."<option value='\'>--Select--</option>

<option value=' ".$sem['no_of_semesters']." '>
".$sem['no_of_semesters']."</option>

</select>";

}


echo $select;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.