Jump to content

Recommended Posts

Posted

I've done a Goggle search and I kind of understand it, but I don't know how to adapt it to my current code. See, I have a reviewindex page that shows both movie and DVD review through a variable (type=dvd or type=movie). It's been a while since I've done some coding so I might be mixing up termanology...

 

Anyway, I'm hoping someone can help me. What I want is to split up the number of reviews listed (probably 30 per page) but I don't know how to do this with my code (sorry for it being so long, but I don't know what to include and not include):

 

><HTML>
<HEAD>

<?php

if ($type == movie) {
echo "<TITLE>Movieman's Guide to the Movies >> Review Index >> Movies</TITLE>";
}

if ($type == dvd) {
echo "<TITLE>Movieman's Guide to the Movies >> Review Index >> DVDs</TITLE>";
}

?>
<META NAME="keywords" CONTENT="movie reviews, movieman, moviemans's guide to the movies, brian oliver, hundreds of movie reviews, review index">
<LINK rel="stylesheet" type="text/css" href="styles.css">
<LINK rel="stylesheet" type="text/css" href="style_extra.css">

<?PHP include ("external/headsection.html"); ?>
</HEAD>
<BODY>
<?php

include("*edited*");

$dbh=mysql_connect (*edited*) or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("$db");

$type = $_GET['type'];

?>
<BASEFONT FACE="Verdana">

<TABLE CLASS="BORDERCOLOR" BORDER="0" ALIGN="CENTER">
<TR>
<?PHP
include ("external/new_header.php");
?>
</TR>

<!-------------------------------------Left Navigation------------------------->

<TR>
<td class="leftside" valign="top">
<table class="leftside">

<?PHP
include ("http://www.moviemansguide.com/external/main_menu.php");
?>

<?PHP
include ("http://www.moviemansguide.com/external/latest_reviews.php");
?>

<?PHP
include ("http://www.moviemansguide.com/external/boxoffice.php");
?>

<?PHP
include ("http://www.moviemansguide.com/external/advertisement.php");
?>

<tr><td><img src="images/spacer.gif" width="140" height="0"></td></tr>

</table>
</td>

<!---------------------------------------Main Area----------------------------->

 <TD CLASS="mainarea" VALIGN="TOP">
   <TABLE CLASS="mainarea" ALIGN="CENTER">

   <TR>
   <TD COLSPAN="2">

<!--------------------------------THE MOVIE----------------------------------------->

<TR>
  <TD>
<TABLE WIDTH="100%" BORDER="0">
<?php

if ($type == movie) {

$titlelist = @mysql_query("SELECT name, movie_reviews.id, year, star_rating, title, list_title FROM critic, movie_reviews WHERE criticid=critic.id ORDER BY list_title ASC");

while ($listing = mysql_fetch_array($titlelist)) {
$id = $listing['id'];
$title = $listing['title'];
$year = $listing['year'];
$name = $listing['name'];
$rating = $listing['star_rating'];

echo"
<TR>
   <TD CLASS='rindex-year'>$year</TD>
   <TD CLASS='rindex-link'><b><a href='reviews/movie/read.php?id=$id'>$title</a></b></TD>
   <TD CLASS='rindex-critic'>$name</TD>
   <TD CLASS='rindex-rating'><img src='images/star_ratings/$rating.gif' HEIGHT='25' ALT='$rating'></TD>
</TR>";

}

}

if ($type == dvd) {

$titlelist = @mysql_query("SELECT name, dvd_reviews.id, year, rating_overall, title, list_title, edition FROM critic, dvd_reviews WHERE criticid=critic.id ORDER BY list_title ASC");

while ($listing = mysql_fetch_array($titlelist)) {
$id = $listing['id'];
$title = $listing['title'];
$edition = $listing['edition'];
$year = $listing['year'];
$name = $listing['name'];
$rating = $listing['rating_overall'];

echo"
<TR>
   <TD CLASS='rindex-year'>$year</TD>
   <TD CLASS='rindex-link'><a href='reviews/DVD/read.php?id=$id'><b>$title</b></a> ($edition)</TD>
   <TD CLASS='rindex-critic'>$name</TD>
   <TD CLASS='rindex-rating'><img src='images/star_ratings/$rating.gif' HEIGHT='25' ALT='$rating'></TD>
</TR>";
}

}


?>
</TABLE>
  </TD>
</TR>

   </TABLE>
 </TD>

</tr>

<tr>
<td valign="CENTER" colspan="3" cellpadding="0" cellspacing="0">

<?PHP
include ("external/new_footer.php");
?>

</td>
</tr>

</table> <!--Closes Body Table-->

</html>

 

Hopefully this wasn't entirely confusing as, like I said, I'm just getting back into this after a few months and my mind is'nt back into it at the moment...

 

Thanks in advance,

Brian

Posted

To be honest pagination code is a pain in the rear. The basics are you first have to figure out how many pages you need in total. You do this by dividing the total number of entries by the number of entries you are displaying per page and rounding it up using ceil(). Now you know how many pages you will have in total.

 

Now it all depends on what you want to do. You could just display a link to all the pages at the bottom including the current page.

 

Or you could display them all but work out the current page and make it inactive as a link and different from the other page numbers.

 

OR .... You get fancy like forums and Lazarus and have it display the first page and last page and then x number of pages either side of the current page. This is where it gets icky.

 

WhenI was writing the code for Lazarus I looked at how SMF did it to get the rough idea and then wrote my own from scratch.

Posted

If I am not mistaken there is an excellent example of this in the "Dummies for MySQL and PHP" book. Don't have it in front of me at the moment but I am sure that's where I saw it.

Posted

Brian,

 

I believe what you are looking for is the SQL limit function :

 

SELECT * FROM `foo` LIMIT 0, 10

 

The limit statement allows you to define a starting record and the number of proceeding records, the above statement returns 10 records from the foo table starting @ 0.

 

You will also need a session variable that contains the maximum number of rows returned by the query with no limit function, the current starting record and a pre determined number of records to display per page.

 

Byron Thomas

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...