jandrews Posted April 10, 2009 Share Posted April 10, 2009 Hey, Does anyone know why this query would only return one row in a table? <?php require_once('Connections/top50.php'); ?> <?php $maxRows_top50 = 10; $pageNum_top50 = 0; if (isset($_GET['pageNum_top50'])) { $pageNum_top50 = $_GET['pageNum_top50']; } $startRow_top50 = $pageNum_top50 * $maxRows_top50; mysql_select_db($database_top50, $top50); $query_top50 = "SELECT hits, title_music, playlist_music FROM flamplayer_musics ORDER BY hits DESC"; $query_limit_top50 = sprintf("%s LIMIT %d, %d", $query_top50, $startRow_top50, $maxRows_top50); $top50 = mysql_query($query_limit_top50, $top50) or die(mysql_error()); $row_top50 = mysql_fetch_assoc($top50); if (isset($_GET['totalRows_top50'])) { $totalRows_top50 = $_GET['totalRows_top50']; } else { $all_top50 = mysql_query($query_top50); $totalRows_top50 = mysql_num_rows($all_top50); } $totalPages_top50 = ceil($totalRows_top50/$maxRows_top50)-1; mysql_free_result($top50); ?> </p> <table width="100%" cellpadding="3" cellspacing="2"> <tr> <td align="center" bgcolor="#121212"><div align="center">Song</div></td> <td align="center" bgcolor="#121212"><div align="center">Band</div></td> <td align="center" bgcolor="#121212">Plays</td> </tr> <?php do { ?> <tr> <td bgcolor="#666666"><a href="../band.php?music=<?php echo urlencode($row_top50['playlist_music']); ?>" class="style2"><a href="backing_track.php?track=<?php echo urlencode($row_top50['title_music']); ?>"> <?php echo ucfirst($row_top50['title_music']); ?></a></td> <td bgcolor="#666666"><a href="../band.php?music=<?php echo urlencode($row_top50['playlist_music']); ?>" class="style2"><?php echo ucfirst($row_top50['playlist_music']); ?></a></td> <td align="center" bgcolor="#666666"><?php echo $row_top50['hits']; ?></td> </tr> <?php } while ($row_top50 = mysql_fetch_assoc($top50)); ?> </table> Any help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/153535-query-only-returning-one-result/ Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 I think it could be something to do with the fact that dowhile runs the do loop before checking the while. You should do it like this instead: while($whatever = mysql_fetch_array($whatever)) { //stuff here... } Quote Link to comment https://forums.phpfreaks.com/topic/153535-query-only-returning-one-result/#findComment-806769 Share on other sites More sharing options...
jandrews Posted April 10, 2009 Author Share Posted April 10, 2009 tried to rearrange that like you said, but it doesnt seem to be that Quote Link to comment https://forums.phpfreaks.com/topic/153535-query-only-returning-one-result/#findComment-806801 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Try deleting: mysql_free_result($top50); Quote Link to comment https://forums.phpfreaks.com/topic/153535-query-only-returning-one-result/#findComment-806821 Share on other sites More sharing options...
jandrews Posted April 10, 2009 Author Share Posted April 10, 2009 Try deleting: mysql_free_result($top50); No That doesn't work either. Quote Link to comment https://forums.phpfreaks.com/topic/153535-query-only-returning-one-result/#findComment-806827 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Ugh. Try putting or die(mysql_error()); after each query... Quote Link to comment https://forums.phpfreaks.com/topic/153535-query-only-returning-one-result/#findComment-806829 Share on other sites More sharing options...
jandrews Posted April 11, 2009 Author Share Posted April 11, 2009 Ugh. Try putting or die(mysql_error()); after each query... There is only 1 query and it does have or die(mysql_error()); after it. hmmmm.... I can't figure this one out Quote Link to comment https://forums.phpfreaks.com/topic/153535-query-only-returning-one-result/#findComment-807636 Share on other sites More sharing options...
fenway Posted April 14, 2009 Share Posted April 14, 2009 Show us the final sql statement. Quote Link to comment https://forums.phpfreaks.com/topic/153535-query-only-returning-one-result/#findComment-809843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.