Here's an interesting problem I've run into today:
I've created a query in my controller that will go out and grab the 3
most viewed projects each user has.
Here is my find as well my variable for the view:
$popular = $this->Project->find('all',
array(
'conditions'=>array('Project.portfolio_id'
=>$user['Portfolio']
['id']),
'order'=>'Project.visits DESC',
'fields'=> array('Project.name',
'Project.description',
'Project.visits', 'Project.slug', 'Project.cover'),
'recursive'=>0,
'limit' => 3
)
);
// add name to option
$popular = array('User'=>'This Users 3 most viewed
Projects') +
$popular;
$this->set('popular', $popular);
As you can see I find all projects that have a Portfolio ID set to the
same Portfolio ID of the user.
It will display the records by how often they've been viewed (visits)
in descending order.
I chose which fields to display as well as limiting it to just the top
3.
This works fine. If I print the variable is set (popular) to the view
my array looks perfect.
The problem I'm having is that when I create a loop to loop through
the three records it only prints the 1st character of each field.
Here's my loop (Just a small one for debugging).
<?php
//$i = 0;
foreach ($popular[2]['Project'] as $project) { ?>
<?php echo $project['name']; ?>
<br />
<?php //$i++; ?>
<?php } ?>
The incrementer that I created isn't being used for this example. I'm
just pulling the data for the 3rd record in the array.
I suppose I should also provide you with the 3rd item in my array so
here it is.
[2] => Array
(
[Project] => Array
(
[name] => Gallery
[description] => This is for testing purposes,
this project will be removed after I have fine-tuned the image display
scripts.
[visits] => 16
[slug] => gallery
[cover] => Sexy-Party.jpg
[id] => 41
)
)
So when I view the page after running the loop this is what is
displayed.
G
T
1
g
S
4
As you can see it's the very first character from each field.
Even more strange is that I filtered down to the name in my loop so,
if nothing else, follow this problem it should have only printed "G"
I'm terribly sorry that this is so long, I wanted to provide you with
as much information as I could.
Also I'm using CakePHP 1.2.0.7692 RC3
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---