Welcome Guest, Not a member yet? Register   Sign In
selecting data from two tables
#4

[eluser]mr lister[/eluser]
Ah yes, I see how that works.

I am still getting over the Dreamweaver / Developer Toolbox way of doing things - using their nested loops.

The M-V-C concept is far different to what I was used too, but I think is it a far better way of doing things.

[Edit]
Actually, the more I think about it, the more confused I am about it... in the foreach loop you would have to have some conditional statement that checks the 'id' value.

Something along the lines of?:
Code:
<?php
// declare a value outside the loop to check question id
// i think you have to declare the variable in the controller
// and pass it to the view??
$id_value = 0;
?>

<?php foreach($questions as $question) ?>

<?php
if ( $id_value != $question->id )
{ // initially $id_value = 0, so condition is true
  // so show the question.
?>
<p><strong>&lt;?php echo $question->questioncontent ?&gt;</strong></p>
&lt;?php
  // since the 'if' statement is true and the question
  // shown the first time, put the $question->id into
  // the $id_value
$id_value = $question->id;
}
?&gt;

&lt;?php echo $question->answercontent ?&gt;

&lt;?php endforeach; ?&gt;

That should work?


Messages In This Thread
selecting data from two tables - by El Forum - 06-09-2011, 02:00 AM
selecting data from two tables - by El Forum - 06-09-2011, 03:58 AM
selecting data from two tables - by El Forum - 06-09-2011, 04:53 AM
selecting data from two tables - by El Forum - 06-09-2011, 05:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB