vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How Do You Do A Loop? (https://vborg.vbsupport.ru/showthread.php?t=51208)

Craigr 04-05-2003 11:48 AM

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

I've been trying for ages now to make the above query loop. This is the first time i've tried to make any SQL.

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

noppid 04-05-2003 01:08 PM

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.

Craigr 04-05-2003 01:21 PM

Quote:

Today at 03:08 PM noppid said this in Post #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.

How would i do any of them. I don't know any SQL i spent about 2 days getting the above to work I created it by looking at other scripts?

Basically i don't know how to do a loop. I've tried, but it doesn't work for me.

Craig

noppid 04-08-2003 04:53 PM

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.

leviw 04-24-2003 11:57 PM

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. =)

filburt1 04-24-2003 11:59 PM

Side note: always use vbdate() instead of date() to take a user's GMT shift into effect.

Logician 04-25-2003 11:23 AM

PHP Code:

$quizresultsDB=$DB_site->query("SELECT totalcorrect, resulttime FROM quiz_results WHERE userid = '$userinfo[userid]' ORDER BY quizid  ASC LIMIT 10");

while (
$quizresults=$DB_site->fetch_array($quizresultsDB)) 
{
//viewed session    
$myquizresults.='Total Correct='.$quizresults[totalcorrect].' - Result Time='.$quizresults[resulttime].'<br>';
}
echo 
$myquizresults


Craigr 04-25-2003 02:13 PM

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'. :D

Thanks again,
Craig


All times are GMT. The time now is 08:31 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00990 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete