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!!

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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.