CodeIgniter Forums
Traditional Mysql Code - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Traditional Mysql Code (/showthread.php?tid=54701)



Traditional Mysql Code - El Forum - 09-20-2012

[eluser]rochellecanale[/eluser]
hey guys just want to ask. Can i integrate the traditional Mysql command in my script?
Like:
Code:
$connect = mysql_connect('localhost','root','','databasename')
or die mysql_error();

$query = "SELECT * FROM sampletable";
while(($row = mysql_fetch_array($query)) !== FALSE){
     echo $row['id'].
     .
     .
     .
     .
}

because in one of my file i want to retrieve my information using this method... And together with that i want to store my information in a multidimensional array inside my while loop.


Traditional Mysql Code - El Forum - 09-20-2012

[eluser]xerobytez[/eluser]
Sure, you can...but why would you want to? CodeIgniter's active record system makes working with databases so much easier and cleaner. Here is an example of what you are doing in active record.

Code:
$result = $this->db->get('sampletable');

if ($result->num_rows()) {
    foreach($result->result_array() as $row) {
        echo $row['id'];
    }
}



Traditional Mysql Code - El Forum - 09-20-2012

[eluser]CroNiX[/eluser]
Have you read the userguide for using the database?
Controller
Code:
//get data from database
$data['tabledata'] = $this->db->get('sampletable')->result_array();
//send it to a view
$this->load->view('some_view', $data);

View
Code:
foreach($tabledata as $row)
{
  echo $row['id'];
}



Traditional Mysql Code - El Forum - 09-20-2012

[eluser]rochellecanale[/eluser]
yes i have read that but the problem is i am implementing a shopping cart which is plugin. And that plugin is written in traditional format. And for retrieving cart list is actually stored in a (two dimensional/multidimensional array) My problem is i cant retrieve my data in my database. I tried active record but it gives me a result of undefined index. i put my array inside the foreach loop.


Traditional Mysql Code - El Forum - 09-20-2012

[eluser]CroNiX[/eluser]
Why not use a cart system that is already written for CI, or use CI's own cart system? You're going to fight an uphill battle here.


Traditional Mysql Code - El Forum - 09-20-2012

[eluser]rochellecanale[/eluser]
yes i want to do that but my problem is it displays all the product details. all i want to do is have a search box that can navigate the selected product. Like in the grocery. When the barcode reader scanned the product it retrieves the product result. How can i do that?