vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   invalid argument (https://vborg.vbsupport.ru/showthread.php?t=63785)

AN-net 04-12-2004 03:59 PM

invalid argument
 
im getting invalid argument for some reason:
heres the error
Quote:

Originally Posted by php
Warning: Invalid argument supplied for foreach() in /home/blah/blah/blah/quiz.php on line 140

PHP Code:

137:        $fquestions$DB_site->query("SELECT quiz_questions.question,quiz_questions.question_id,quiz_answers.answer,quiz_answers.correct FROM ".TABLE_PREFIX."quiz_questions LEFT JOIN quiz_answers ON (quiz_questions.question_id=quiz_answers.question_id) WHERE quiz_questions.quiz_id='".$_REQUEST['q']."' AND quiz_questions.active='1' AND quiz_answers.active='1'");
138:        while($question$DB_site->fetch_array($fquestions))
139:        {
140:            foreach($question['answer'] as $answer)
141:            {
142:                exec_switch_bg();
143:                eval('$ansbits .= "' fetch_template('quiz_correctansbits') . '";');
144:            } 


Xenon 04-12-2004 04:07 PM

are you sure the variable $question['answer'] is an array?
it has to be one :)

AN-net 04-12-2004 04:37 PM

well isnt fetch_array making the results into an array?

Xenon 04-12-2004 04:44 PM

$question is an array, but you are using $question['answer'] as argument

Xenon 04-12-2004 04:44 PM

it seems like you should just don't use foreach at all, and just use the fetch array loop :)

AN-net 04-12-2004 08:14 PM

but it will only display one answer for each question even though there might be for five or six of them.

Xenon 04-12-2004 08:51 PM

as i said, you have to make sure what type of variable is $question['answer']
if it's an array you can use foreach, if not, then you have tu use something else to spread it on your board.

I can just explain what lead to the error, not what exactly the vars are :)

AN-net 04-12-2004 11:15 PM

could u give me a suggestion on how to make it that for each answer?
plz oh mighty php intelligent one:)

Xenon 04-13-2004 12:39 PM

well, personally i'd put the answers into an array, and then serialize that array when storing into the db.

later when you catch it, you have to unserialize it again.

or you can use the way vb devs did it with poll questions by seperating the strings via ||| and then using implode and explode functions.

the serialize function should be explained in the tips and trix forums here, the implode version is used often in vb and should be quite selfexplaining

you may also look up php.net for infos about.


All times are GMT. The time now is 09:03 PM.

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.00978 seconds
  • Memory Usage 1,731KB
  • 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_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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