Welcome Guest, Not a member yet? Register   Sign In
Displaying a table of results
#11

[eluser]Thorpe Obazee[/eluser]
[quote author="mdcode" date="1239093841"]As above

Code:
foreach($query as $row){
echo "<tr>";
echo "<td>". $row->id ."</td>";
echo "<td>". $row->name ."</td>";
echo "<td>". $row->date_required ."</td>";
echo "<td>". $row->job_status ."</td>";
echo "</tr>";
}
[/quote]

Code:
foreach($query->result() as $row){
echo "<tr>";
echo "<td>". $row->id ."</td>";
echo "<td>". $row->name ."</td>";
echo "<td>". $row->date_required ."</td>";
echo "<td>". $row->job_status ."</td>";
echo "</tr>";
}

try this.
#12

[eluser]mdcode[/eluser]
Turns up a page with no styling stating:

Code:
Fatal error: Call to a member function result() on a non-object in C:\xampp\htdocs\lipro\system\application\views\default\pages\projects_reports.php on line 35

Line 35 is:
Code:
foreach($query->result() as $row){
#13

[eluser]Thorpe Obazee[/eluser]
does the sql query produce any data?
#14

[eluser]mdcode[/eluser]
Running through phpmyadmin, yes it does, 10 records (which is how many there should be).

On the page, nothing.
#15

[eluser]Thorpe Obazee[/eluser]
oh wait. I didn't notice that you used the result() method already in the model method.

what does $this->db->last_query() produce?

and it's what you're using with phpmyadmin?

Edit: are you still using the result() in the model... from your first post you are... the next post you aren't.
#16

[eluser]Thorpe Obazee[/eluser]
Code:
$this->db->select("lip_projects.id, lip_projects.customer, lip_projects.date_required, lip_projects.job_status, lip_customers.id, lip_customers.name");
$this->db->join('lip_customers', 'lip_customers.id = lip_projects.customer', 'LEFT');
$this->db->order_by('lip_projects.id', 'DESC');
$this->db->limit(10);
return $this->db->get('lip_projects');

Code:
// what does this produce?
echo $query->num_rows();
#17

[eluser]mdcode[/eluser]
Quote:oh wait. I didn't notice that you used the result() method already in the model method.

Edit: are you still using the result() in the model... from your first post you are... the next post you aren't.

I'm not, but either way it makes no difference.

Quote:what does $this->db->last_query() produce?

Code:
SELECT `lip_projects`.`id` , `lip_projects`.`customer` , `lip_projects`.`date_required` , `lip_projects`.`job_status` , `lip_customers`.`id` , `lip_customers`.`name`
FROM (
`lip_projects`
)
LEFT JOIN `lip_customers` ON `lip_projects`.`customer` = `lip_customers`.`id`
ORDER BY `lip_projects`.`id` DESC
LIMIT 10

Quote:and it's what you're using with phpmyadmin?

It is.
#18

[eluser]mdcode[/eluser]
[quote author="bargainph" date="1239095929"]
Code:
$this->db->select("lip_projects.id, lip_projects.customer, lip_projects.date_required, lip_projects.job_status, lip_customers.id, lip_customers.name");
$this->db->join('lip_customers', 'lip_customers.id = lip_projects.customer', 'LEFT');
$this->db->order_by('lip_projects.id', 'DESC');
$this->db->limit(10);
return $this->db->get('lip_projects');

Code:
// what does this produce?
echo $query->num_rows();
[/quote]

It echoes: 10
#19

[eluser]Thorpe Obazee[/eluser]
Honestly, I am quite stumped.

Code:
function get_last_ten_entries()
{
$this->db->select("lip_projects.id, lip_projects.customer, lip_projects.date_required, lip_projects.job_status, lip_customers.id, lip_customers.name");
$this->db->join('lip_customers', 'lip_customers.id = lip_projects.customer', 'LEFT');
$this->db->order_by('lip_projects.id', 'DESC');
$this->db->limit(10);
return $this->db->get('lip_projects');
}

Code:
// in the controller method

$query = $this->yourmodel->get_last_ten_entries();
if ($query->num_rows() > 0)
{
    foreach ($query->result() as $row)
    {
      echo $row->id;
    }

}
#20

[eluser]mdcode[/eluser]
Me too, but neverthelss I have it now, thanks!!

Code is as follows...

MODEL
Code:
function get_last_ten_entries()
{
$this->db->select('projects.pid, projects.customer, projects.date_required, projects.job_status, customers.id, customers.name');
$this->db->from('projects');
$this->db->join('customers', 'projects.customer = customers.id', 'left');
$this->db->order_by('projects.pid', 'DESC');
$this->db->limit(10);

return $this->db->get();
}

VIEW:
Code:
foreach($query->result() as $row){
echo "<tr>";
echo "<td>". $row->pid ."</td>";
echo "<td>". $row->name ."</td>";
echo "<td>". $row->date_required ."</td>";
echo "<td>". $row->job_status ."</td>";
echo "</tr>";
}

I'm not quite sure why it works but it does and so I'm happy...



The only thing about this is that the first column on the table echoes the project id number, however if I just had id in the foreach loop (with the id column in the projects table being named id), then it echoed the id of the customer, not the project. I only got around this by calling the id column in the projects table pid, not really ideal to me but it works -- any ideas how I can change it back to id and still have this work?

Many thanks for your help and time.




Theme © iAndrew 2016 - Forum software by © MyBB