hello, how can I display a data (ex. course) in a drop-down list whenever I add a data? thanks!

hello, how can I display a data (ex. course) in a drop-down list whenever I add a data? thanks!

hi...

from database? or any other way?

can u explain be detail?

from data base, u can get this way.....

$course="aaaaa"; //example...
<select name="course" title="course" value="<?php echo $course; ?>" >
<option value="">Select course</option>
<?php
while($row=mysql_fetch_array($result))
{
?>
<option value="<?php echo $row['course']; ?>"><?php echo $row['course']; ?></option>
<?php
}
?>
</select>

thanks..

how can i "connect" test1 to test 2? example, i already have an id for the test1. i want to connect test2's id to test1... i dont know how to implement it in PHP... XD

thanks..

how can i "connect" test1 to test 2? example, i already have an id for the test1. i want to connect test2's id to test1... i dont know how to implement it in PHP... XD

Hi...

here what is test1 and test2 ?
explain plz?

ok sorry. lets say test1 == course. test2 == topic. I want to add a course in the database and display it to a drop-down menu(done). After selecting the desired course, we will now add a topic to that course. so from there, if we want to view a course, the topic added to that course will display.

im creating a test bank btw. :)

ok sorry. lets say test1 == course. test2 == topic. I want to add a course in the database and display it to a drop-down menu(done). After selecting the desired course, we will now add a topic to that course. so from there, if we want to view a course, the topic added to that course will display.

im creating a test bank btw. :)

HI..
first i want to know ..this is right? plz check...

1)display courses in first select box..
2) afeter selecting the course u need to display topics related to that course in second select box..

if the above procedure is right try to using this one...


in this select box display all courses frm database..

<select name="course" id="course" onchange="switchProduct();">
<?php
		include("config.php");
		$row=mysql_query("select distinct course from courses  ")or die(mysql_error());
		
?>
        <?php if(!$cu==""){ ?>
 <option value="<?php echo $cu ; ?>"><?php echo $cu;?></option><?php }else { ?> 
<option value="Select One">Select One</option><?php } ?>
<?php 
		while($res=mysql_fetch_array($row))
		{
		$course1=$res['course'];
		if($cu!=$course){
?>
          <option value="index.php?cu=<?php echo $course1 ; ?>&topic=<?php echo $topic; ?>"><?php echo $course1;?></option>
<?php }}
?>
            </select>

after by using onchange event u can display topics.....
here is the code...

<script language="javascript">
	 function switchProduct()
	 {
	 if(window.document.form1.course.options.selectedIndex!=0)
	 
	 window.location=window.document.form1.course.options[window.document.form1.course.options.selectedIndex].value
	 }
	  
	 
	  </script>

here is second selectbox code.....

$cours= $_GET['course'];
<select name="topic" id="topic">
     
<?php
$course
if($course==""){?>
<option value="Select One">Select Course</option>
<?php }else  { ?> 
 <option value="<?php echo $topic;?>"><?php echo $topic;?></option>
<?php }
		while($res=mysql_fetch_array($row1))
		{
		$topic1=$res['topic']; 
		if($topic==$topic1){}else{
?>
          <option value="<?php echo $topic1;?>"><?php echo $topic1;?></option>
<?php }}
?>
        </select>

If u confuse plz excuse....just ask if u want any doubts....

This article has been dead for over six months. Start a new discussion instead.