How do I loop through and output all the values in the array? The code I have stops after the first output.
$select_top = array($wpdb->get_results($wpdb->prepare( "SELECT * FROM `wp_top_voted` WHERE `todays_date`= CURDATE() ORDER BY `number_votes` DESC LIMIT 10", OBJECT )));
if ($select_top){
$i = 1;
foreach($select_top as $select_top_one){
$select_top_one->post_id;
$post_id_top[$i] = $select_top_one[$i]->post_id;
$number_votes[$i] = $select_top_one[$i]->number_votes;
$size = array(380,220);
?>
<div class="top-layout">
<div class="top-layout-row">
<div class="top-layout-cell">
<?php //remove background color. Make box look like widget.
?>
<div class="top-layout-cell">
<h4 class="top-video-title">
<a href="<?php the_permalink(); ?>">
<?php echo get_the_title( $post_id_top[$i] ); ?>
</a>
</h4>
<a href="<?php the_permalink(); ?>">
<?php echo get_the_post_thumbnail( $post_id_top[$i], $size ); ?>
</a>
<?php $i++; echo $i++; ?>
</div>
</div>
You just loop all the results and print them out. You don't need to auto increment the loop as the foreach runs for as long as there are results. This seems to be Wordpress, so take a look at the get_posts function https://codex.wordpress.org/Template_Tags/get_posts. This function works as what you're trying to do but you only need to insert your $args and then execute You'll have your array and you can loop that.