benji87 Posted April 27, 2007 Share Posted April 27, 2007 Hey guys, could someone please show me the best way to make this into a loop: if ($sk > 0) { echo "<td width=100 bgcolor=\"$row_colour\" class='navigation'><div align='centre'>Subject Knowledge</div></td>"; } else { echo ""; } if ($afl > 0) { echo "<td width=100 bgcolor=\"$row_colour\" class='navigation'><div align='centre'>Assessment for learning</div></td>"; } else { echo ""; } if ($lst > 0) { echo "<td width=100 bgcolor=\"$row_colour\" class='navigation'><div align='centre'>Learning style theories</div></td>"; } else { echo ""; } Im not sure how to do it as eah result is based on a different variable. Link to comment https://forums.phpfreaks.com/topic/48913-loop/ Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 um... what type of loop? what are you expecting to get out? what do you have going in? Link to comment https://forums.phpfreaks.com/topic/48913-loop/#findComment-239699 Share on other sites More sharing options...
benji87 Posted April 27, 2007 Author Share Posted April 27, 2007 Ok i want it to echo <td width=100 bgcolor=\"$row_colour\" class='navigation'><div align='centre'>$VARIABLE</div></td> WHILE an array of results returned from a database = 1 So for every result returned from the query that = 1 echo the name of that result. Link to comment https://forums.phpfreaks.com/topic/48913-loop/#findComment-239711 Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 o...k...? while($row=mysql_fecth_assoc($query)){ if($sk > 0){ echo "<td width=100 bgcolor='$row[colour]' class='navigation'><div align='centre'>$row[VARIABLE]</div></td>"; }elseif($afl > 0){ echo "<td width=100 bgcolor='$row[colour]' class='navigation'><div align='centre'>$row[VARIABLE]</div></td>"; }elseif($lst > 0){ echo "<td width=100 bgcolor='$row[colour]' class='navigation'><div align='centre'>$row[VARIABLE]</div></td>"; } } Link to comment https://forums.phpfreaks.com/topic/48913-loop/#findComment-239716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.