ashrafzia Posted October 25, 2007 Share Posted October 25, 2007 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 https://forums.phpfreaks.com/topic/74687-problem-with-displaying-the-correct-result/ Share on other sites More sharing options...
trq Posted October 25, 2007 Share Posted October 25, 2007 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 https://forums.phpfreaks.com/topic/74687-problem-with-displaying-the-correct-result/#findComment-377594 Share on other sites More sharing options...
redarrow Posted October 25, 2007 Share Posted October 25, 2007 <?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 https://forums.phpfreaks.com/topic/74687-problem-with-displaying-the-correct-result/#findComment-377598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.