TheTitans Posted December 14, 2008 Share Posted December 14, 2008 I have a mysql query followed by some html and a while loop <?php // count($versions) is equal to 5 for ($i = 0; $i < count($versions); $i++) { ?> <div id="<?php echo $versions[$i] ?>"> <table> <tr> <td colspan="10" class="dex_header"><strong>Attacks:</strong></td> </tr> <tr> <td style="width:5%; text-align:center">RB</td> <td style="width:10%; text-align:center">Move</td> <td style="width:5%; text-align:center">Type</td> <td style="width:5%; text-align:center">Power</td> <td style="width:5%; text-align:center">Accuracy</td> <td style="width:10%; text-align:center">PP</td> <td style="width:5%; text-align:center">Class</td> <td style="text-align:center">Description</td> </tr> <?php while ($row2 = $db->fetchArray($result3)) { $ver = explode(",", $row2['versions']); if (in_array($versions2[$i], $ver)) { ?> <tr> <td class="dex<?php echo $versions[$i] ?>_sub"><?php echo $row2['level'] ?></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><a href="attacks.php?id=<?php echo $row2['move_id'] ?>"><?php echo $row2['name'] ?></a></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><img src="images/types/<?php echo $row2['type'] ?>.gif" alt="" /></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><?php echo $dex->powerCheck($row2['power']); ?></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><?php echo (($row2['accuracy'] != 0) ? $row2['accuracy'] . '%' : '--' ) ?></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><?php echo $row2['pp'] ?> / <?php echo $dex->calculateMaxPP($row2['pp']) ?></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><img src="images/types/<?php echo $row2['class'] ?>.gif" alt="<?php echo $row2['class'] ?>" title="<?php echo $row2['class'] ?>" /></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><?php echo $row2['blurb_dp'] ?></td> </tr> <?php } // end while loop } ?> </table> </div> <?php // end for loop } ?> The program loops through 5 times. The first time the results are displayed in the proper table format. The second, third, fourth, and fifth time, nothing gets displayed. My theory is that the results from the mysql query have already been looped through once and that's all it can do. Right now the query is outside of the for loop. Everything works if the query is inside the for loop right before the while loop, but that's not good coding practice. So what can I do to fix this?[/code] Link to comment https://forums.phpfreaks.com/topic/136887-displaying-results-multiple-times-from-single-mysql-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 14, 2008 Share Posted December 14, 2008 http://us.php.net/mysql_data_seek Link to comment https://forums.phpfreaks.com/topic/136887-displaying-results-multiple-times-from-single-mysql-query/#findComment-714943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.