[PHP] Need help to loop true the results

Status
Not open for further replies.

AndroidApps

Active Member
326
2010
4
0
Thanks in advance!

The goal is to display a list of items (websites) sorted by most votes.
I've got this (from here):
<?php $items = ThumbsUp::items('
')->open(TRUE)->orderby('votes_pct_up desc')->limit(3)->get() ?>

This would result in:
PHP:
array (
  0 => 
  array (
    'id' => 653,
    'name' => '[quote] scandic',
    'closed' => false,
    'date' => 1325620171,
    'votes_up' => 76,
    'votes_down' => 36,
    'votes_pct_up' => 67.8571,
    'votes_pct_down' => 32.1429,
    'votes_balance' => 40,
    'votes_total' => 112,
  ),
  1 => 
  array (
    'id' => 654,
    'name' => '[quote] mozunk',
    'closed' => false,
    'date' => 1325620171,
    'votes_up' => 75,
    'votes_down' => 39,
    'votes_pct_up' => 65.7895,
    'votes_pct_down' => 34.2105,
    'votes_balance' => 36,
    'votes_total' => 114,
  ),
  2 => 
  array (
    'id' => 655,
    'name' => '[quote] clarklab',
    'closed' => false,
    'date' => 1325620171,
    'votes_up' => 58,
    'votes_down' => 33,
    'votes_pct_up' => 63.7363,
    'votes_pct_down' => 36.2637,
    'votes_balance' => 25,
    'votes_total' => 91,
  ),
)

I can't figure out how to get this to display on a webpage.. :facepalm:
Reference page: http://tpbmirrors.org/dev.php
 
6 comments
PHP:
foreach($items as $item) {
print_r($item); //print array

echo $item['id']; //echo id
echo $item['name']; //echo name 

}
 
Oh well!


PHP:
foreach($items as $item) {
//print_r($item); //print array
echo $item['id'].' has ';
echo $item['votes_up'].' positive votes and '; //echo positive votes
echo $item['votes_down'].' negative votes '; //echo negative votes
echo '<br />'; //linebreak to make things look a bit better
}
Result:

653 has 76 positive votes and 36 negative votes
654 has 75 positive votes and 39 negative votes
655 has 58 positive votes and 33 negative votes

I hope you got the point. Check tutorials related to arrays in PHP and this will look a lot simpler :)
 
Status
Not open for further replies.
Back
Top