Hello everyone! :-)
I'm working with CodeIgniter (PHP Framework MVC) and SQLSRV drivers on a WAMP environment. I have a problem when I try to send sqlsrv_fetch_array() to my view...
After installing the drivers (etc.) I had to leave the "database" configuration file included with codeIgniter and to created a new helper named "database_helper". I created this function:
function DBconnect() { $serverName = 'Server\sql'; $connectionInfo = array('Database'=>'DBname'); $conn = sqlsrv_connect( $serverName, $connectionInfo); return $conn;}
Then, I added a model "UsersMod". This model should let me display data from a database.
function Accounts() { $this->load->helper('database'); $conn = DBconnect(); $tsql= "SELECT * FROM accounts"; $objQuery = sqlsrv_query( $conn, $tsql ); while($data = sqlsrv_fetch_array($objQuery)) { $tab[] = array( $data["DN"], $data["Login"]); } return $tab; } // I tried to fill a table with my data...
And then I can call the UsersMod in my controller, to send the result's query to my view to display a table.
function index() { $this->load->helper('database'); $this->load->model("UsersMod"); $tab["Users"] = $this->UsersMod->Accounts(); $this->load->view('GP/obsoleteAdm',$tab); }
But in my view, it does not understand what my data 'Users' is:
foreach($Users as $item) { echo $tr."<td>".$item["Name"]."</td> <td>".$item[0]."</td> <td><input type='checkbox' onClick='php_funtion()');' name='exclude'></td> </tr>";}
That's not a secret, PHP don't get what I'm trying to do. I am very confused with HOW to put my query result in a table without overwriting everytime the data in the "While". I think my problem comes from "How to manage the query result"...
Thank you in advance for your time!!
Please note that when I put all my code in the view, I got a great table ;-) but I can't use an
<input type='checkbox'
like if it can't know which row is which row.
Sorry for my english... I did my best!