I am querying the database for different values of prizes for an online loyalty scheme.
I know this is going to be a sort of easy question but Im still getting used to PHP so here goes…
This is what I have so far:
<?php $sqlprize="SELECT prizeid FROM wp_scloyalty_orders WHERE userid = '$user_id'";
$resultprize=mysql_query($sqlprize); ?>
<?php while($rows=mysql_fetch_array($resultprize)){
query_posts('post_type=prizes&showposts=-1&p='.$rows['prizeid'].''); while (have_posts()) : the_post();
$my_meta = get_post_meta($post->ID,'_my_meta',TRUE);
//echo $my_meta['pointsvalue'];
endwhile;
wp_reset_query();
} ?>
Basically I want it so each time it loops the database query it adds the value (my_meta[‘pointsvalue’] to an array, which I can use outside of the loop…
Thanks!
EDIT—————–
<?php $purchasevalue=array(); ?>
<?php $sqlprize="SELECT prizeid FROM wp_scloyalty_orders WHERE userid = '$user_id'";
$resultprize=mysql_query($sqlprize); ?>
<?php while($rows=mysql_fetch_array($resultprize)){
query_posts('post_type=prizes&showposts=-1&p='.$rows['prizeid'].''); while (have_posts()) : the_post();
$my_meta = get_post_meta($post->ID,'_my_meta',TRUE);
$purchasevalue[] = $my_meta['pointsvalue'];
endwhile;
wp_reset_query();
} ?>
<?php echo array_sum($purchasevalue) ?>
Thanks guys, sorted it in the end… is this a good way of doing it?
You can use array_push to add values to an array
Hope that’s what you’re looking for