Question

    <?php
    function __autoload($classname) {
        $filename = "./". $classname .".php";
        include_once($filename);
    }
    class empidload{

        //function for load combo box
        public function loadCombo(){
            $connection=new connectdb();
            $con=$connection->getCon();
            $query = "SELECT * FROM department";
            $result = mysql_query($query) or die(mysql_error());

            while($row=mysql_fetch_assoc($result)){
                echo "<option value='".$row["dno"]."'>".$row["detail"]."</option>";
            }
        }


    }


    ?>
<html>
<body>
 <select name="department" id="department" style="width:204px;"  onchange="change(this);">
                        <?php
                    $emp = new empidload();// calling function for load combo boxes
                    $emp.loadCombo();
                ?>                      
                </select> 
</body>
</html>   

Here I try to load combobox from MySQL database. I wrote function and call it. But it doesn't work.can anyone help me please? actually what i want to load comboboxes from database table. And also I want to change another combobox according to the value of first combobox. Please help me.

Était-ce utile?

La solution

You're mixing MySQL functions, you can't do that.

You're using mysql_query and other mysql_ functions but with a mysqli_ DB connection.

Change $result = mysql_query($query) or die(mysql_error()); to
$result = mysqli_query($con,$query) or die(mysqli_error());

and while($row=mysql_fetch_assoc($result)){

to

while($row=mysqli_fetch_assoc($result)){

Plus, as stated in Notulysses' answer:

change $emp.loadCombo(); to $emp->loadCombo();

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top