Jump to content

jmp98

New Members
  • Posts

    5
  • Joined

  • Last visited

jmp98's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello everyone. thanks for your help on this topic. after trying a few different things and talking to some other people, this is the final code i came up with which works successfully global $post; $content = ''; $args = array( 'post_type' => 'funder', 'post_status' => 'publish', // optional 'posts_per_page' => -1 ); $lists = get_posts($args); $highest_ascend=array(); $highest=0; $highest_id=array(); $completed = array(); $i=0; $j=0; if($lists) { foreach($lists as $list) { $list_id = $list->ID; $goal = $this->get_goal_amount($list_id); $total = $this->get_amount_raised($list_id); $percent=($total/$goal)*100; if($percent < 100 && $percent > 0 ) { $highest_ascend[$j]= $percent; $highest_id[$j] = $list_id; $j++; } if($percent==100) { $completed[$i] = $list_id; $i++; } } } $num = count($highest_ascend); for($m=0; $m < $num; $m++ ) { for ( $n=$m; $n < $num; $n++ ) { if($highest_ascend[$m] < $highest_ascend[$n]) { $t1= $highest_ascend[$m]; $highest_ascend[$m]=$highest_ascend[$n]; $highest_ascend[$n]=$t1; $t2=$highest_id[$m]; $highest_id[$m]=$highest_id[$n]; $highest_id[$n]=$t2; } } } for($i=0;$i<3;$i++) { $content.=get_the_title( $highest_id[$i] )." ".round($highest_ascend[$i], 2).' % <br>'; } return $content; } thanks for your suggestions anyway - very helpful
  2. Yes i realise that, i have been trying to integrate parts of it but am struggling to get it to work successfully. i have tried a number of different ways getting different ideas from the code you provided but it never seems to work properly.
  3. sorry i'm relatively new to php and i'm not sure how to integrate the code you have given me into the original code. my original code returns a variable value and manages to get the highest value without sorting the data. can someone explain to me how this works or how to integrate the codes together so that when the variable data is inputted from the below code, i get the highest three percentages outputted in the same format as the $content in the original code. $args = array( 'post_type' => 'funder', 'post_status' => 'publish', // optional 'posts_per_page' => -1 ); $lists = get_posts($args); as you can see in the original code, $lists becomes the new array - or have i misunderstood something?? sorry if i'm horribly confusing!!!
  4. will this return three values though. for example if i had a=10/100, b=2/10, c=20/50, d=1.5/10, e=3/5, f=5/100, g=33/100 i want the function to return content as e 60% c 40% g 33% this data is obviously just random example data where it would be $total/$goal in its current format it just returns e 60%
  5. what part of this code do i need to edit in order for the funder with the second highest percentage to be returned?? function get_donated_list() { global $post; $content = '';$args = array('post_type' => 'funder','post_status' => 'publish', // optional 'posts_per_page' => -1); $lists = get_posts($args);$highest=0;$highest_id=0; $completed = array();$i=0;if($lists) {foreach($lists as $list) {$list_id = $list->ID;$goal = $this->get_goal_amount($list_id);$total = $this->get_amount_raised($list_id);$percent=($total/$goal)*100; if($highest < $percent && $percent < 100 ){$highest = $percent;$highest_id = $list_id;}if($percent==100){$completed[$i] = $list_id;$i++;}}} if($highest_id){$content=get_the_title( $highest_id )." ".round($highest, 2).'%'; } return $content;} i have tried changing a few parts in the code but it still returns the id witht the highest percentage EDIT i have had a look around myself and i think what i actually want is a foreach with a limit of 3 loops but i don't know where to add it. i want it to loop the process so that it returns the three highest percentages one error in the code is: if($percent==100) should have actually read if(0 < $percent)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.