Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-05-2003, 11:48 AM
Craigr's Avatar
Craigr Craigr is offline
 
Join Date: May 2002
Location: Ayr, Scotland
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 04-05-2003, 01:08 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 04-05-2003, 01:21 PM
Craigr's Avatar
Craigr Craigr is offline
 
Join Date: May 2002
Location: Ayr, Scotland
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #4  
Old 04-08-2003, 04:53 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 04-24-2003, 11:57 PM
leviw leviw is offline
 
Join Date: Jan 2003
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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. =)
Reply With Quote
  #6  
Old 04-24-2003, 11:59 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Side note: always use vbdate() instead of date() to take a user's GMT shift into effect.
Reply With Quote
  #7  
Old 04-25-2003, 11:23 AM
Logician's Avatar
Logician Logician is offline
 
Join Date: Nov 2001
Location: inside vb code
Posts: 4,449
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #8  
Old 04-25-2003, 02:13 PM
Craigr's Avatar
Craigr Craigr is offline
 
Join Date: May 2002
Location: Ayr, Scotland
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:19 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.09013 seconds
  • Memory Usage 2,236KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete