what's the best way to loop this?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

When the user clicks either "next" or "previous" I want to go that way.
For the time being, the next question will appear below the current one.

What I am aiming it is one of two things.
To show only one question at a time.
OR, show the already answered question with the proper answer minus the

$ask is from the two dim array.
'pick' is the button name associated with the answers.

print "<div class='big'>";
 echo makeTable($ask,$i);
 print "<div class=chk>";
 echo $_POST['pick'];
 if ($answr != $ask[$i][6] and $answr != "") echo " is wrong";
 print "<form name='mover' action='' method='post'>";
   print "<input type='submit' name='forward' value='previous'>";
   print "<input type='submit' name='forward' value='next'>";
 print "</form>";
 print "</div>";
print "</div>";

Re: what's the best way to loop this?

Quoted text here. Click to load it


Shouldn't this line....

if ($answr != $ask[$i][6] and $answr != "") echo " is wrong";

...be entered as...

if ($answr != $ask[$i][6] && $answr != "") echo " is wrong";

Hope this helps


Re: what's the best way to loop this?

Quoted text here. Click to load it

In this case it does not matter.

PHP has both the and operator and the && operator, the only difference being
that they operate at different precedences.

Look up logical operators in the manual and follow the link to operator

I think the OPs question lies at a level far below this though, that of
basic design. What does he actually want to do? The code example bears
little relationship to the actual question. In any case he cannot even get
the form element right. Oh, hang on, yes, he seems to have got that bit.

Re: what's the best way to loop this?

Andy schreef:
Quoted text here. Click to load it


Or simply use parenthesis:
if ( ($answr != $ask[$i][6]) && ($answr != "")){
  echo " is wrong";

and avoid the whole precedence issue.

But in this case it doesn't matter because the != comparison takes
precedence over both AND and &&.

(Personally I prefer the use of paranthesis: it is always clear.)

That aside: I cannot really follow the OP question. Too much
code/context is missing to give meaningful assistance.

Erwin Moller

"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Site Timeline