/ Published in: PHP
I needed to know the first time a user took a quiz and the last quiz they took. I utilized php count() and as I iterated through the array, I incremented a variable ($i) which before the loop, I already set it to 1. If $i was equal to 1, I printed it out. If I was equal to the total count, I printed it out. Everything else got ignored.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$firstQuizSql = $wpdb->get_results("SELECT id, datetaken, person FROM aw_wpsqt_all_results WHERE person_name='$user_info->user_login' ORDER BY id"); $i = 1; foreach ($firstQuizSql as $firstQuizResult) { //first quiz result if ($i == 1) { echo $firstQuizResult->id . " "; } //last quiz result echo $firstQuizResult->id . " "; } $i++; }