Hello, I tried looking around but couldn’t find anything on this subject. I have v2.1.0 build 20100810 and have a temple (called from an embed tag) with PHP allowed on input. I ran a query and wanted to use a foreach loop with the data, but when I do so, the temple fails to process EE template tags. As soon as I remove the foreach statement, the template then is able to use the tags. Is this because there is something wrong with the foreach? Or is there a setting I am missing?
Thank you!
OK, I did some other checking around–it fails because my results array is empty. Tested a few queries I selected at random, like: $this->EE->db->query(“SELECT message_id FROM exp_message_data”);
And they always return something like:
CI_DB_mysql_result Object
(
[conn_id] => Resource id #38
[result_id] => Resource id #83
[result_array] => Array
(
)
[result_object] => Array
(
)
[current_row] => 0
[num_rows] => 37
[row_data] =>
)I have another query running the page that returns data from exp_members just fine.
What’s your code to generate that?
Look at the CI docs on the database class: http://ellislab.com/codeigniter/user-guide/database/active_record.html
you need something like:
$query = $this->EE->db->select('foo')->get('bar');
if ($query->num_rows() !== 0)
{
foreach ($query->result() as $row)
{
var_dump($row);
// or
echo $row->foo; // for the var you're trying to get
}
}I hope that makes sense. The CI docs should help.
-greg
Here is one thing I’ve tried when retrieving number of new PM’s:
<?php
echo "<pre>";
$this->EE->db->select('private_messages')->where('member_id', $this->EE->session->userdata['member_id']);
$new_messages = $this->EE->db->get('exp_members');
print_r($new_messages);
echo "</pre>
<p>”;
?>Which gives
CI_DB_mysql_result Object
(
[conn_id] => Resource id #38
[result_id] => Resource id #66
[result_array] => Array
(
)
[result_object] => Array
(
)
[current_row] => 0
[num_rows] => 1
[row_data] =>
)But, now this works:
$mquery = $this->EE->db->query("SELECT private_messages FROM exp_members WHERE member_id = '".$this->EE->session->userdata['member_id']."'");
echo "<pre>";
print_r($mquery);
echo "</pre>
<p>”;However, any query run after that in the query() method returns proper number of rows, but does not return result array or object.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.