1
    <?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.

nbanic
  • 1,270
  • 1
  • 8
  • 11
saku
  • 35
  • 11
  • I noticed you don't have any `
    ` tags.
    – Funk Forty Niner May 09 '14 at 04:50
  • Plus, it's hard to say what your DB connection is. If your DB connection is `mysqli_`, then it doesn't mix/work with `mysql_` functions. Add error reporting to the top of your file(s) `error_reporting(E_ALL); ini_set('display_errors', 1);` to see if it yields any errors. – Funk Forty Niner May 09 '14 at 04:53
  • in my code i have added form tags. here i forgot to paste that tags sorry. – saku May 09 '14 at 04:56
  • this is my DB connection code: class connectdb{ var $con=NULL; public function getCon(){ $con=mysqli_connect('localhost','root', '','phpprj'); if (!$con) { die('Could not connect!: ' .mysqli_connect_error()); } echo 'Successfully Connected. '; return $con; } } ?> – saku May 09 '14 at 04:58
  • Did you try the answer given below? Where it states to use `$emp->loadCombo();` instead of `$emp.loadCombo();` – Funk Forty Niner May 09 '14 at 05:00
  • Oh I see a major error now. 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. – Funk Forty Niner May 09 '14 at 05:01
  • 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)){` – Funk Forty Niner May 09 '14 at 05:03
  • i tried this also.$emp->loadCombo(); – saku May 09 '14 at 05:05
  • That isn't the only problem with your code. See new comments above. Did you change it to those? – Funk Forty Niner May 09 '14 at 05:06
  • You're welcome. I will make an answer then. – Funk Forty Niner May 09 '14 at 05:08
  • i want another help as well. i want to load another combo box. if i select IT from department combobox, i want to fill section combobox from database with section of the IT department. in my section table there are lot of sections relevant to several departments – saku May 09 '14 at 05:12
  • You could use a `WHERE` clause for that. I.e.: `WHERE department='dept1'` for example. Yet you may have to ask another question. My comments/answer has solved your issue. Consider ticking the checkmark on it till it turns green to properly close the question and marked as solved. – Funk Forty Niner May 09 '14 at 05:13
  • i am new to here. pls can u tell me where is the checkmark? – saku May 09 '14 at 05:20
  • It's next to my answer below, it's white grayed outline tick/checkmark under both little arrows. Once you click it, it will turn green. – Funk Forty Niner May 09 '14 at 05:22

1 Answers1

0

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();

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141