Problem with drop down list

Discussion in 'PHP' started by shubham123, Jun 5, 2007.

  1. #1
    Hi all
    Please help me to Solve this problem:confused:.

    I am doing small project i which i have one select list(drop-down) ,in which i get the data from database .Select list contained the name of the student.(from student info table) .When you select one name from the list ,it create dynamic table on the same page where the selected name is added.My problem is that when you select name and it is added to table ,the selected name should be deleted from drop down list only and not from the database.

    please help me its urgent
     
    shubham123, Jun 5, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    
    while ($studentinfo = mysql_fetch_assoc($query))
    {
        if ($_REQUEST['name'] == $studeninfo['name'])
        {
            continue;
        }
    
        echo '<option value="'. $studentinfo['name'] .'">'. $studentinfo['name'] .'</option>'. "\n";
    }
    
    PHP:
    If this doesn't help... post your code. All I can do is guess.
     
    nico_swd, Jun 5, 2007 IP
  3. shubham123

    shubham123 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi
    thank you for your quick reply .I already tried this solution
    can you suggest any other way to pop up the alert which says the selefcted value is already existed in the table.
    Than k you
     
    shubham123, Jun 5, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Post your code.
     
    nico_swd, Jun 5, 2007 IP
  5. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Since he's dealing with client side, I think he needs javascript instead of php.

    Here try this:
    <html>
    <head>
    <title>test</title>
    </head>
    <script>
    function addnew(newname)
    {
    	if(newname)
    	{
    		var content = document.getElementById("valueholder");
    		var tableholder = document.getElementById("tableholder");
    		var dynamictable = "<table border=1 width=200><tr><td>";
    		dynamictable += newname + "<br>" + content.innerHTML;
    		dynamictable += "</td></tr></table>";
    		tableholder.innerHTML = dynamictable;
    		content.innerHTML = newname + "<br>" + content.innerHTML;
    		
    	}
    }
    </script>
    <body>
    <div id="valueholder" style="display:none"></div>
    <div id="tableholder"></div>
    <select name="studentList" onchange="addnew(this.options[this.selectedIndex].value); this.options[this.selectedIndex].value=''">
    <option value="">Select a name</option>
    <option value="student name 1">student name 1</option>
    <option value="student name 2">student name 2</option>
    <option value="student name 3">student name 3</option>
    <option value="student name 4">student name 4</option>
    <option value="student name 5">student name 5</option>
    </select>
    </body>
    </html>
    PHP:
    All you need to do is replace dropdown list with the one you have in your database.
     
    Vbot, Jun 5, 2007 IP