Jump to content

Paging system (VERY NOOB QUESTION)


KvickaN

Recommended Posts

Hello everyone!

 

I'm completely new to PHP and Databases. I've managed to do some nice work by reading, but now I've encountered a problem I can't solve.

 

I made a site with trailers and got tierd of adding them manually. So I created a form which sends the trailer info to my database.

 

There's now trailers in specific organized genres. But the list is beginning to get really big so I wanted to show just 10 trailers per page. And so I found out I could use a paging system which I ALMOST got working. Just one last thing that needs to be fixed and that is when I click on next page "http://www.xxxxxxxx.com/test.php&page=2" it doesn't show the content. While "http://www.xxxxxxxx.com/test.php" does.

 

So I just need that next button to work, I don't know if theres something missing or what it is...

 

Note: I'm new to all this so please excuse my very very bad coding.

 

Here is my code:

 

test.php

<link rel="stylesheet" type="text/css" media="all" href="http://www.xxxxxxxxxxxxx.n.nu/createdfiles/trailers/style-twentyten.css" />
<link rel="stylesheet" type="text/css" media="all" href="http://www.xxxxxxxxxxxxx.com/paginate.css" />

<?php

$rpp = 10; // results per page
$adjacents = 4;

$page = intval($_GET["page"]);
if(!$page) $page = 1;

$reload = $_SERVER['PHP_SELF'];

// connect to your DB:
$link_id = mysql_connect("server","username","my password");
mysql_select_db("database");

// select appropriate results from DB:
$sql = "SELECT * FROM blablabla WHERE Genre LIKE '%Drama%' ORDER BY `blablabla`.`sort` DESC LIMIT 0, 9999";
$result = mysql_query($sql, $link_id);

// count total number of appropriate listings:
$tcount = mysql_num_rows($result);

// count number of pages:
$tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number

$count = 0;
$i = ($page-1)*$rpp;
while(($count<$rpp) && ($i<$tcount)) {
    mysql_data_seek($result,$i);
    $query = mysql_fetch_array($result);

    // output each row:
    echo "<br />--------------------------------------------------------------------------------------------------------<br /><br />";
?><strong> <img src=" <?php echo $query['Poster'];?>" /><?php
  echo "<br /> <br />";

//////////////////////////////
//SHOW TITLE, YEAR AND GENRE//
//////////////////////////////

  echo "<H1>";	
  echo $query['Title'];
  echo "<br /> <br />";
  echo "</h1>";
?></strong> <?php
  echo "<H2>";
  echo $query['Year'];
  echo "</H2>";
  echo "<br />";
  echo "<H3>";
  echo $query['Genre'];
  echo "</H3>";
?>
<a href="
<?php

//////////////////////////////
//SHOW IMDB, ACTORS AND PLOT//
//////////////////////////////

  echo $query['IMDB'];
?>
" target="_self">Link to IMDb</a>
<?php
  echo "<br /> <br />";
  echo "<H2>Stars:</H2>";
  echo "<br />";
  echo "<H3>";
  echo $query['Actors'];
  echo "</H3>";
  echo "<br />";
  echo "<H2>Plot:</H2>";
  echo "<br />";
  echo "<H3>";
  echo $query['Plot'];
  echo "</H3>";
  echo "<br /> <br />";
  echo "<H2>";

////////////////
//SHOW TRAILER//
////////////////

?>
<div id="<?php echo $query['ID'];?>" style="display: none;">
<?php
  echo $query['Youtube'];
  echo "</div>";
?>
<a href="javascript:ReverseDisplay('<?php echo $query['ID'];?>')">Click to show/hide trailer.</a>
<?php
  echo "</H2>";
  echo "<br /> <br />";

    $i++;
    $count++;
}

// call pagination function:
include("paginate_one.php");
echo paginate_one($reload, $page, $tpages);
?>

<?php
////////////////////////////////
//SCRIPT FOR SHOW/HIDE TRAILER//
////////////////////////////////
?>

<script type="text/javascript" language="JavaScript"><!--
function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}
//--></script>

 

paginate_one.php

<?php
/*************************************************************************
php easy :: pagination scripts set - Version One
==========================================================================
Author:      php easy code, www.phpeasycode.com
Web Site:    http://www.phpeasycode.com
Contact:     webmaster@phpeasycode.com
*************************************************************************/
function paginate_one($reload, $page, $tpages) {

$firstlabel = "First";
$prevlabel  = "Prev";
$nextlabel  = "Next";
$lastlabel  = "Last";

$out = "<div class=\"pagin\">\n";

// first
if($page>1) {
	$out.= "<a href=\"" . $reload . "\">" . $firstlabel . "</a>\n";
}
else {
	$out.= "<span>" . $firstlabel . "</span>\n";
}

// previous
if($page==1) {
	$out.= "<span>" . $prevlabel . "</span>\n";
}
elseif($page==2) {
	$out.= "<a href=\"" . $reload . "\">" . $prevlabel . "</a>\n";
}
else {
	$out.= "<a href=\"" . $reload . "&page=" . ($page-1) . "\">" . $prevlabel . "</a>\n";
}

// current
$out.= "<span class=\"current\">Page " . $page . " of " . $tpages . "</span>\n";

// next
if($page<$tpages) {
	$out.= "<a href=\"" . $reload . "&page=" .($page+1) . "\">" . $nextlabel . "</a>\n";
}
else {
	$out.= "<span>" . $nextlabel . "</span>\n";
}

// last
if($page<$tpages) {
	$out.= "<a href=\"" . $reload . "&page=" . $tpages . "\">" . $lastlabel . "</a>\n";
}
else {
	$out.= "<span>" . $lastlabel . "</span>\n";
}

$out.= "</div>";

return $out;
}
?>

 

Here you can view a test of it all in action: http://www.mansgullberg.com/test.php please dont hack my site :)

 

I'm thankfull for all of your answers! Really nice forum this!  :)

 

/kvickan

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.