I am trying to populate my DataTable based on a dropdownbox selection in a Codeigniter view, however in my controller i have my instantiation of my datatable. So in a nutshell im trying to send post data from my view to my controller to have my results show up in the datatable itself. Below is the code for the views and controllers:
query.php (first view):
Once the user selects a category from the drop down and hits search it displays the view 'data.php' Here is the code for it:
data.php (Second View)
Here is my controller:
query.php (controller)
Im getting an error: "Undefined index: childCategoryID" when i fire up firebug.
ANY HELP IS GREATLY APPRECIATED!!!!!!
Thanks,
Brad
query.php (first view):
..... ..... <div id="body"> <br/> <div align="center" height="600px"> Select a product category <br/><br/> <?php $server="xxxxx"; $username="xxxxx"; $password="xxxxx"; $conn=mysql_connect($server, $username, $password) or die ("Cannot connect to mysql server: ".mysql_error()); $dbname = 'xxxx'; @mysql_select_db($dbname) or die( "Unable to select database"); $query="SELECT childCategoryID,childCategoryName FROM Categories1"; $result = mysql_query ($query); echo "<form name=form method=post action='index.php/query/data'>"; echo "<select name=\"childCategoryID\">"; while($nt=mysql_fetch_assoc($result)){ echo "<option value=$nt[childCategoryID]>$nt[childCategoryName]</option>"; } echo "</select>";// Closing of list box echo " <input type=submit value=Search name=button> </form>"; echo "<form name=form2 method=post action='index.php/query/data'>"; echo "Enter your search critera: <br/>"; echo "<input type=text id=searchCritera name=searchCritera />"; echo "<input type=submit value=Search name=btnSearch />"; echo "</form>"; ?> </div> </div> ... ....
Once the user selects a category from the drop down and hits search it displays the view 'data.php' Here is the code for it:
data.php (Second View)
.... .... <body id="dt_example"> <div id="container"> <h1 align="center"><img src="/images/bluelynx_logo.jpg" alt="Blu Lynx Communications" ></img></h1> <div id="body"> <br/> <div align="center" height="600px"> <table cellpadding="2.5" cellspacing="2.5" class="display" id="example"> <thead> <tr> <th height="5" width="5%">Product ID:</th> <th height="5" width="25%">Product Name:</th> <th height="5" width="15%">Child Category:</th> <th height="5" width="10%">Order Number:</th> <th height="5" width="15%">Brand:</th> <th height="5" width="10%">Mfg Number:</th> <th height="5" width="30%">Product Description:</th> </tr> </thead> <tbody> <tr> <td colspan="5" class="dataTables_empty">Loading data from server</td> </tr> </tbody> <tfoot> <tr> <th>Product ID:</th> <th>Product Name:</th> <th>Child Category:</th> <th>Order Number:</th> <th>Brand:</th> <th>Mfg Number:</th> <th>Product Description:</th> </tr> </tfoot> </table> ... ....
Here is my controller:
query.php (controller)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Query extends CI_Controller { private $the_user; // <-------<--------<--------<-------<-------- // ^ public function __construct() // ^ { // ^ parent::__construct(); // ^ // ^ // if the person accessing this controller is logged in // ^ if($this->ion_auth->logged_in()) { // ^ // ^ // get the user object // ^ $data->the_user = $this->ion_auth->user()->row(); // ^ // ^ // put the user object in class wide property--->---->----- $this->the_user = $data->the_user; // load $the_user in all displayed views automatically $this->load->vars($data); } else // person not logged in { // send back to the root site redirect('/'); } } public function index() { $this->load->view('query'); } public function logout() { // log current user out and send back to public root $this->ion_auth->logout(); redirect('/'); } public function data() { $this->load->view('data'); } public function getdatabyajax() { $childCategoryID=$_POST['childCategoryID']; $this->load->library('Datatables'); $this->datatables->select('productID,productName,childCategoryName,orderNum,brand,mfgNum,productDescription'); /*$this->datatables->from('Products1');*/ $this->datatables->where('childCategoryID', '$_POST['$childCategoryID']); echo $this->datatables->generate(); } }
Im getting an error: "Undefined index: childCategoryID" when i fire up firebug.
ANY HELP IS GREATLY APPRECIATED!!!!!!
Thanks,
Brad