Jump to content

pagination of my results isnt working.


bradholland

Recommended Posts

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>

Link to comment
Share on other sites

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() );

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.