<lesson>
<objective>
<model>
<strategy />
<strategy />
</model>
<model>
<strategy />
<strategy />
</model>
</objective>
<objective>
<model>
<strategy />
<strategy />
</model>
<model>
<strategy />
<strategy />
</model>
</objective>
</lesson>
Here are my PHP/MySQL statements:
// Get all objectives pertaining to the lesson and their assessments. $oQuery = "SELECT description, assessment, objective_id FROM objectives WHERE fk_lesson_id = $_GET[lid]"; $oResult = mysqli_query($link, $oQuery); // Get all strategies pertaining to the objective and their parent models. $sQuery = "SELECT strategy_name, model_name, fk_objective_id FROM strategies, models, objective_strategies, objectives WHERE objectives.fk_lesson_id = $_GET[lid] AND strategies.strategy_id = objective_strategies.fk_strategy_id AND objective_strategies.fk_objective_id = objectives.objective_id AND strategies.fk_model_id = models.model_id ORDER BY objective_strategies.fk_objective_id AND strategies.fk_model_id ASC"; $sResult = mysqli_query($link, $sQuery);
All is fine so far; I've tested the query, and it works. Now we come to the PHP loops to make it display as noted above:
<label>Learning Objectives:</label>
<ol class="objectives">
<?php while($oRow = mysqli_fetch_array($oResult, MYSQLI_ASSOC)) { ?>
<li class="objective">
<label><?php echo $oRow['description']; ?></label>
<p><label>Assessment Criteria:</label><?php echo $oRow['assessment']; ?></p>
<div class="inputRow">
<div class="leftCol">
<label>Teaching Model<?php if($sCount > 1) { echo 's'; } ?>:</label>
</div>
<div class="rightCol">
<label>Strateg<?php if($sCount > 1) { echo 'ies'; } else { echo 'y'; } ?>:</label>
</div>
<ul class="none">
<?php while($sRow = mysqli_fetch_array($sResult, MYSQLI_BOTH)) {
if($sRow['fk_objective_id'] == $oRow['objective_id']) { ?>
<li>
<div class="leftCol">
<?php echo $sRow['model_name']; ?>
</div>
<div class="rightCol">
<?php echo $sRow['strategy_name']; ?>
</div>
</li>
<?php } } ?>
</ul>
</div>
</li>
<?php } ?>
<div class="clearfix"></div>
</ol>
The objective blocks filter by lesson number and iterate just fine. For some reason, though, only the strategies and models for the first objective display. All other objectives have no models or strategies listed. When I added the comparison of $oRow['objective_id'] to $sRow['fk_objective_id'] I was able to get it to stop listing *all* the strategies in the first objective, but they did not move to their respective associated objectives either.
I would also like to only show each model name once, instead of repeating it for each strategy of that model type. I'm thinking this is where something like array_unique() would come in handy?
(I'm also still trying to figure out the best method for counting the items returned so the labels have proper pluralization when appropriate, but that's a minor issue.)
Any help would be appreciated; thank you!

New Topic/Question
Reply




MultiQuote






|