The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
How Do You Do A Loop?
Code:
// Quiz Addon $quiznamez=$DB_site->query_first("SELECT quiztitle, description, quizid, timestamp FROM quiz ORDER BY quizid ASC LIMIT 10"); $quizresults=$DB_site->query_first("SELECT totalcorrect, resulttime FROM quiz_results WHERE userid = '$userinfo[userid]' ORDER BY quizid ASC LIMIT 10"); $totalquestions=$DB_site->query_first("SELECT COUNT(quizid) AS questions FROM quiz_questions WHERE quizid='$quiznamez[quizid]'"); $questions = $totalquestions[questions]; $numA = $quizresults[totalcorrect]; $numB = $questions; $percentage = $numA/$numB*100; $dateposted = date("D j M Y, g:i A",$quiznamez[timestamp]); $taken = date("D j M Y, g:i A",$quizresults[resulttime]); $quizname .="<tr><td bgcolor='#F1F1F1' width=20%><normalfont><b>$quiznamez[quiztitle]</b></normalfont> <smallfont>[ <a href=\"quiz.php?s=&quizid=$quiznamez[quizid]\">Take Quiz</a> ]<br><smallfont>$quiznamez[description]<br><i>Created: $dateposted</i></smallfont></td><td bgcolor='#F1F1F1' width=20%><normalfont>$quizresults[totalcorrect] correct from $questions questions. Giving a percentage of $percentage%.</normalfont><br><smallfont><i>Quiz completed: $taken</i></smallfont></td></tr>\n"; // End Quiz Addon The above is an addon i was making for the quiz. In the member profile i hope to pull the quiz names and the person's results and put them at the bottom of the profile. At the moment the above just pulls one quiz name and one result. I want it to keep going until all the quiz names/results are displayed. I think you use while, but i'm not sure. Could someone help? Also could you let me know if any of the above is wrong. Thanks Craig |
#2
|
|||
|
|||
Get the record count and use a for loop or...
Get the whole table and use a for each loop or... Get the highest of the QuizID and use it in a for loop. There's more then one way to skin a cat. But you need to weigh each option for over head and such to decied. |
#3
|
||||
|
||||
Quote:
Basically i don't know how to do a loop. I've tried, but it doesn't work for me. Craig |
#4
|
|||
|
|||
I'm sorry I didn't get back to ya. I took a closer look and it's not something I could work out without much more detail.
I'm tied up in the middle of a painting nightmare since I last posted. Sorry I couldn't be of more help. |
#5
|
|||
|
|||
I'm pretty new to PHP myself so am not much help, but the first thing I think when I see all that is, "No wonder hes confused.."
Use a smaller experiment, meet and marry the php.net website, and try to have little php kids with it if at all possible. Best way to learn is by taking tiny chunks and tweaking them, so you know what happens when you move each piece. Then go back and add details AFTER you have a working, backed up example. Good luck. =) |
#6
|
|||
|
|||
Side note: always use vbdate() instead of date() to take a user's GMT shift into effect.
|
#7
|
||||
|
||||
PHP Code:
|
#8
|
||||
|
||||
Thanks all. I was going to use this for the members profile, but the addon has been created already in the quiz thread.
I will have to read my book 'php and mysql for dummies'. Thanks again, Craig |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|