Page 1 of 1
how to run loop inside array
Posted: Mon Jun 07, 2010 8:28 am
by manojsemwal1
Hai iam trying to run while loop inside array how to do this. code are like,...
Code: Select all
$xoption = array(
//Page => ('Answer Variable Name', 'Answer Label')
'1' => array('answer_1_var_name', 'Answer Name 1', 'answer_2_var_name', 'Answer Name 2', 'answer_3_var_name', 'Answer Name 3', 'answer_4_var_name', 'Answer Name 4'),
);
// i want to use
$i=1;
$b=mysql_fetch_array($result2);
xoption = array(
'$i' => array('1', '$b[ans1]','2', '$b[ans1]''3', '$b[ans1]''4', '$b[ans1]'),
);
Thanks
Re: how to run loop inside array
Posted: Mon Jun 07, 2010 10:14 am
by Jonah Bron
I don't quite understand. Could you clarify what you're trying to accomplish?
Re: how to run loop inside array
Posted: Mon Jun 07, 2010 10:29 am
by markusn00b
Yeh... what?
Also, remember to use quotes, be they single od double, around array indexes. If you don't, I will hunt you down!
Code: Select all
// Good
echo $array['your_key'];
// BAD!
echo $array[your_key];
Unless of course you have defined the appropriate constants (something I doubt).
Mark.
Re: how to run loop inside array
Posted: Mon Jun 07, 2010 10:46 am
by Jonah Bron
...I will hunt you down!...
And you don't want that: just take a look at his avatar!

Re: how to run loop inside array
Posted: Tue Jun 08, 2010 1:27 am
by manojsemwal1
Sorry for inconvenient
actually iam doing online exam assesment project in there iam trying to get value from database and store that in Array.
//without using database it will like....
session_start();
$total_pages = 6;
$xoption = array(
// Page => ('Answer Variable Name', 'Answer Label')
'1' => array('answer_1_var_name', 'Answer Name 1', 'answer_2_var_name', 'Answer Name 2', 'answer_3_var_name', 'Answer Name 3', 'answer_4_var_name', 'Answer Name 4'),
'2' => '',
'3' => '',
'4' => '',
'5' => '',
'6' => '',
);
echo '<form name="quiz" action="?page=' . $next_page . '" method="post">
<b>Questions PAGE ' . $current_page . '</b><br>
<input type="radio" name="' . $current_page . '" value="' . $xoption[$current_page]['0'] . '">' . $xoption[$current_page]['1'] . '<br>
<input type="radio" name="' . $current_page . '" value="' . $xoption[$current_page]['2'] . '">' . $xoption[$current_page]['3'] . '<br>
<input type="radio" name="' . $current_page . '" value="' . $xoption[$current_page]['4'] . '">' . $xoption[$current_page]['5'] . '<br>
<input type="radio" name="' . $current_page . '" value="' . $xoption[$current_page]['6'] . '">' . $xoption[$current_page]['7'] . '<br>
<br><input type="submit" name="submit" value="Continue to Page ' . $next_page . ' >"> ';
// i want to use fetch value from database.
$i=1;
$b=mysql_fetch_array($result2);
xoption = array(
'$i' => array('1', '$b[ans1]','2', '$b[ans1]''3', '$b[ans1]''4', '$b[ans1]'),
);
so how can i use it.....
Thanks