0

I'm having issues getting this data from within a codeigniter Controller.

    $q = $this->db->get('offers_orders');
    $this->db->select('total');
    $this->db->where('order_number', $orderid);


    $orderdata = $q->result_array();

    $orderamount = $orderdata[0]['total'];

Do you see anything wrong with this code ?.

1
  • what issue is it that you are having? Commented Jul 10, 2013 at 11:14

3 Answers 3

2

Yes, Try :

$this->db->select('count(*) as total', false);
$this->db->where('order_number', $orderid);
$q = $this->db->get('offers_orders');

OR,

$q = $this->db->select('count(*) as total', false)->where('order_number', $orderid)->get('offers_orders');
Sign up to request clarification or add additional context in comments.

Comments

0

You need first to defined your select and where method then you call the get() method which are used for get data.

Like this:

$this->db->select('total');
$this->db->where('order_number', $orderid);
$q = $this->db->get('offers_orders');

And as I see from your query, you need to fetch only one result and for it better solution is to use row() function because this function returns a single result row.

Like this:

$orderdata = $q->row();
$orderamount = $orderdata->total;

Also to learn more about it you can read this acticle.

Comments

-1
 <!DOCTYPE html>
<html>
<body>

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<br> id: ". $row["id"]. " - Name: ". $row["firstname"]. " " . $row["lastname"] . "<br>";
     }
} else {
     echo "0 results";
}

$conn->close();
?> 

</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.