bradholland Posted August 1, 2010 Share Posted August 1, 2010 Hey Guys, In this portion of my code I have tried to implement pagination, as the results try to display a page with over 100 mp3's with flash players on teh page, and of course the page just dies. However my attempt at pagination isnt actually working. can anyone help this noob? <? // how many rows to show per page $rowsPerPage = 20; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $query = " SELECT val FROM ax_music " . " LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Error, query failed'); // print the random numbers while($row = mysql_fetch_array($result)) { echo $row['val'] . '<br>'; } $row2 = mysql_query("SELECT * FROM ax_music ORDER BY 'sort' ASC"); while($row = mysql_fetch_array($row2)){ ?> <tr> <td><?=$row[title];?></td> <td> <embed src= "musicplayer2.swf" quality="high" width="300" height="52" allowScriptAccess="always" wmode="transparent" type="application/x-shockwave-flash" flashvars= "valid_sample_rate=true&external_url=./music/<?=$row[mp3];?>" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed> </td> <td> <? if($row[visible] == 0){ echo "<strong>Not Playlisted</strong><br /> <a href=\"index.php?page=musicplayer&showid=$row[id]\">Add To Playlist</a>"; }else{ echo "<strong>Playlisted</strong><br /> <a href=\"index.php?page=musicplayer&hideid=$row[id]\">Remove From Playlist</a>"; } ?> </td> <td><a href="index.php?page=musicplayer&deleteid=<?=$row[id];?>"><strong>Delete</strong></a></td> <td><a href="./music/<?=$row[mp3];?>"><strong>Download</strong></a></td> </tr> <? } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/209492-pagination-of-my-results-isnt-working/ Share on other sites More sharing options...
Andy17 Posted August 1, 2010 Share Posted August 1, 2010 $row2 = mysql_query("SELECT * FROM ax_music ORDER BY 'sort' ASC"); Aren't you missing a WHERE clause? Also, you should really use mysql_real_escape_string() when you grab a value for a query from the URL ($pageNum). Quote Link to comment https://forums.phpfreaks.com/topic/209492-pagination-of-my-results-isnt-working/#findComment-1093825 Share on other sites More sharing options...
bradholland Posted August 1, 2010 Author Share Posted August 1, 2010 hhhm, i dont really know, or understand. can you pooint me to something i should be reading to get a grasp pf how to fix this? thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/209492-pagination-of-my-results-isnt-working/#findComment-1093929 Share on other sites More sharing options...
Pikachu2000 Posted August 1, 2010 Share Posted August 1, 2010 First, change the short open tags to the full <?php open tags, and change the quick echo <?= tags to the full syntax <?php echo $var; ?>. Then, separate the query string from the query excution, so you can echo it along with any errors. $query = "SELECT `whatever` FROM `table` WHERE `value` = 'something'"; $result = mysql_query( $query ) or die( '<br />Query string ' . $query . '<br />Produced error: ' . mysql_error() ); Quote Link to comment https://forums.phpfreaks.com/topic/209492-pagination-of-my-results-isnt-working/#findComment-1093930 Share on other sites More sharing options...
Skewled Posted August 1, 2010 Share Posted August 1, 2010 http://www.w3schools.com/php/php_mysql_where.asp That will give you an example of the WHERE clause. Quote Link to comment https://forums.phpfreaks.com/topic/209492-pagination-of-my-results-isnt-working/#findComment-1093932 Share on other sites More sharing options...
.josh Posted August 1, 2010 Share Posted August 1, 2010 From the looks of your code, I assume your goal here is to only show 20 rows at a time and have some add/remove/delete links for each one. 1) It looks like you are running two separate queries: 1 with pagination offset/limits and one without. With the first query with the pagination offsets all you are doing is echoing out some column called "val". It looks like you need to remove the 2nd query altogether and move the add/remove/delete links into your first loop. 2) Your pagination offset relies on your $_GET['page'] variable. Well it looks like in your script you are using the 'page' url parameter for something else like signifying which content to display. So it looks like you need to pick a different variable to use for your pagination offset 3) I don't see anywhere in your script where you are actually generating any pagination links. Take a look at this tutorial about pagination .. I think maybe you aren't quite understanding what all goes into pagination. Quote Link to comment https://forums.phpfreaks.com/topic/209492-pagination-of-my-results-isnt-working/#findComment-1093933 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.