[RESOLVED] cut my page up into more than one page
hi
im wanting to cut my search page up to cut down on memory use. can anyone help
so instead of one page i have more than one page like google when a search is done
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>My Videos Site</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>
<div id="mainwrap">
<?php include("header.php"); ?>
<?php include("leftnav.php"); ?>
<div id="contentwrap">
<div id="breadcrumb">
<a href="#">Home</a> :: <a href="#">Category</a> :: This Page
</div>
<div id="content">
<h2>
</style>
</head>
<table border="1" width="62%" height="126" BORDERCOLOR=white>
<?php
/* Change next two lines */
$db="vdidb";
$link = mysql_connect(server:port, 'user', 'login');
if (! $link)
die(mysql_error());
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$id = "%".$_GET["search"]."%";
$result = mysql_query( "SELECT vidnumber, titleid, hd, year,starring1,videotitle,starring2, directedby, filmplot1,dirid,starrid1,starrid2, trilogy,age, Runningtime,WantToWatch FROM videolist WHERE WantToWatch LIKE '".mysql_real_escape_string("True")."'")
or die(mysql_error());
while($row = mysql_fetch_array($result)){
// echo $row['videotitle'];
$num_rows = mysql_num_rows($result);
// <td><?php echo $row['vidnubmer']; ?></td>
<td width="20%" rowspan="4" height="120" BORDERCOLOR=white><p align="center"><img border=0 src="/vidpics/<?php echo $row['videotitle'];?>web.jpg" <?php</p></td>
<td width="20%" height="19" BORDERCOLOR=white><p align="center">ID:<?php echo $row['vidnumber']; ?></td>
<td width="60%" colspan="3" height="19" BORDERCOLOR=white><p align="center"><b><?php echo $row['videotitle']; ?></b></td>
</tr>
<tr>
<td width="20%" height="14" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/title/<?php echo $row['titleid']; ?>" target="_top"><?php echo $row['titleid']; ?></a></td>
<td width="20%" height="14" BORDERCOLOR=white><p align="center">Age <?php echo $row['age']; ?></td>
<td width="20%" height="14" BORDERCOLOR=white><p align="center"><?php echo $row['year']; ?></td>
<td width="20%" height="14" BORDERCOLOR=white><p align="center"><?php echo $row['Runningtime']; ?>mins</td>
</tr>
<tr>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/name/<?php echo $row['dirid']; ?>" target="_top"><?php echo $row['directedby']; ?></td>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/name/<?php echo $row['starrid1']; ?>" target="_top"><?php echo $row['starring1']; ?></td>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/name/<?php echo $row['starrid2']; ?>" target="_top"><?php echo $row['starring2']; ?></td>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><?php echo $row['hd']; ?></td>
</tr>
<tr>
<td width="80%" height="38" colspan="4" BORDERCOLOR=white><?php echo $row['filmplot1']; ?></td>
</tr>
<tr>
<td width="80%" height="38" colspan="5" BORDERCOLOR=white><p align="center">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p></td>
</tr>
<?php
}
?>
</table>
<p align="center">There are <?php echo $num_rows ?> videos from result.</p><P>
Re: cut my page up into more than one page
what you're thinking of is called pagination. you can take a look at a post made by visualAd about it here. and this is a search for pagination on this forum, if you want some more to read about.
Re: cut my page up into more than one page
hi all
i have had not internet access all week what fun:down::down:
any ways i found a example to play around with and better understand pagination but now im stuck can someone please look at my code below as it dont create the page.. i think i may have missed somthing somewere
PHP Code:
<html>
<head><title>Display Records</title>
<style type="text/css">
td {font-family: tahoma, arial, verdana; font-size: 10pt }
</style>
</head>
<body>
<? // database connection info
$conn = mysql_connect('localhost','user','password') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('vdidb',$conn) or trigger_error("SQL", E_USER_ERROR);
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM videolist";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 200;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages){
// set current page to last page
$currentpage = $totalpages
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$sql = "SELECT VidNumber, videotitle FROM videolist LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
// echo data
echo $list['vidnumber'] . " : " . $list['videotitle'] . "<br />";
} // end while
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
?>
</body>
</html>
Re: cut my page up into more than one page
what do you mean, it doesn't create the page? do you get an error? does nothing show up at all?
Re: cut my page up into more than one page
when i try to run the page i get the below in the webpage and not the list of videos from mysql
PHP Code:
// set current page to last page
$currentpage = $totalpages
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$sql = "SELECT VidNumber, videotitle FROM videolist LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
// echo data
echo $list['vidnumber'] . " : " . $list['videotitle'] . "<br />";
} // end while
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
?>
</body>
</html>
__________________
Re: cut my page up into more than one page
don't use short tags. they are deprecated and usually disabled. use regular PHP tags:
PHP Code:
<?php
//your PHP code
?>
Re: cut my page up into more than one page
hi i have now taken out all the tags but still having the same problem
PHP Code:
<html>
<head><title>Display Records</title>
<style type="text/css">
td {font-family: tahoma, arial, verdana; font-size: 10pt }
</style>
</head>
<body>
<?
$conn = mysql_connect('localhost','user','password') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('vdidb',$conn) or trigger_error("SQL", E_USER_ERROR);
$sql = "SELECT COUNT(*) FROM videolist";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
$rowsperpage = 200;
$totalpages = ceil($numrows / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages){
$currentpage = $totalpages
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
$sql = "SELECT VidNumber, videotitle FROM videolist LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
while ($list = mysql_fetch_assoc($result)) {
echo $list['vidnumber'] . " : " . $list['videotitle'] . "<br />";
}
$range = 3;
if ($currentpage > 1) {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
$prevpage = $currentpage - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " [<b>$x</b>] ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
}
?>
</body>
</html>
Re: cut my page up into more than one page
.. no, you haven't. this is a short tag:
you're using them. use the normal tags as I said in my last post.
Re: cut my page up into more than one page
changed it to below and got it working after playing around a little with other stuff on there
thanks kows
Code:
<?php
//your PHP code
?>
Re: cut my page up into more than one page
finished code if anyone want to use it
PHP Code:
<html>
<head><title>Display Records</title>
<style type="text/css">
td {font-family: tahoma, arial, verdana; font-size: 10pt }
</style>
</head>
<body>
<?php
$conn = mysql_connect('localhost','user','password') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('vdidb',$conn) or trigger_error("SQL", E_USER_ERROR);
$sql = "SELECT COUNT(*) FROM videolist";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
$rowsperpage = 50;
$totalpages = ceil($numrows / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages){
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
$sql = "SELECT vidnumber, videotitle FROM videolist LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
while ($list = mysql_fetch_assoc($result)) {
echo $list['vidnumber'] . " : " . $list['videotitle'] . "<br />";
}
$range = 3;
if ($currentpage > 1) {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
$prevpage = $currentpage - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " [<b>$x</b>] ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
}
?>
</body>
</html>
Re: cut my page up into more than one page
hi
im wanting to add a search query to my page how can i do this please
below is my search query without page split i use on my site
PHP Code:
$id = "%".$_GET["search"]."%";
$result = mysql_query( "SELECT videotitle, vidnumber, titleid, hd, year,starring1,starring2, directedby, filmplot1,dirid,starrid1,starrid2, trilogy,age, Runningtime FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."'")
or die(mysql_error());
while($row = mysql_fetch_array($result)){
below is the query use for when splitting pages and adding links
PHP Code:
$sql = "SELECT vidnumber, titleid, hd, year,starring1,videotitle,starring2, directedby, filmplot1,dirid,starrid1,starrid2, trilogy,age, Runningtime,WantToWatch FROM videolist LIMIT $offset, $rowsperpage" ;
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$num_rows = mysql_num_rows($result);
// while there are rows to be fetched...
while ($row = mysql_fetch_assoc($result)) {
i just need to merge these two together so i can have best of both worlds
Re: cut my page up into more than one page
You can use the new one you're using and add "WHERE videotitle LIKE ..." before the LIMIT statement.
PHP Code:
$sql = "SELECT vidnumber, titleid, hd, year,starring1,videotitle,starring2, directedby, filmplot1,dirid,starrid1,starrid2, trilogy,age, Runningtime,WantToWatch FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."' LIMIT $offset, $rowsperpage";
Also I don't know how many columns you have in the table but you might want to consider just using SELECT * FROM.
If you spare something like only 4 or 5 rows it's actually overhead for the database engine.
Re: cut my page up into more than one page
hi
thanks for that, i now have a problem with pagination part.
its not working with the search bit... im stuck:sick:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>My Videos Site</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>
<div id="mainwrap">
<?php include("header.php"); ?>
<?php include("leftnav.php"); ?>
<div id="contentwrap">
<div id="breadcrumb">
<a href="#">Home</a> :: Main Title Page </div>
<div id="content">
<h2>
</style>
</head>
<table border="1" width="62%" height="126" BORDERCOLOR=white>
<?php
$conn = mysql_connect('localhost','user','password') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('vdidb',$conn) or trigger_error("SQL", E_USER_ERROR);
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM videolist";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 5;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
}
// end if
// if current page is greater than total pages...
if ($currentpage > $totalpages){
// set current page to last page
$currentpage = $totalpages;
}
// end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
}
// end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$id = "%".$_GET["search"]."%";
$sql = "SELECT vidnumber, titleid, hd, year,starring1,videotitle,starring2, directedby, filmplot1,dirid,starrid1,starrid2, trilogy,age, Runningtime,WantToWatch FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."' LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
// while there are rows to be fetched...
while ($row = mysql_fetch_assoc($result)) {
// <td><?php echo $row['vidnubmer']; ?></td>
<td width="20%" rowspan="4" height="120" BORDERCOLOR=white><p align="center"><img border=0 src="/vidpics/<?php echo $row['videotitle'];?>web.jpg" <?php</p></td>
<td width="20%" height="19" BORDERCOLOR=white><p align="center">ID:<?php echo $row['vidnumber']; ?></td>
<td width="60%" colspan="3" height="19" BORDERCOLOR=white><p align="center"><b><?php echo $row['videotitle']; ?></b></td>
</tr>
<tr>
<td width="20%" height="14" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/title/<?php echo $row['titleid']; ?>" target="_top"><?php echo $row['titleid']; ?></a></td>
<td width="20%" height="14" BORDERCOLOR=white><p align="center">Age <?php echo $row['age']; ?></td>
<td width="20%" height="14" BORDERCOLOR=white><p align="center"><?php echo $row['year']; ?></td>
<td width="20%" height="14" BORDERCOLOR=white><p align="center"><?php echo $row['Runningtime']; ?>mins</td>
</tr>
<tr>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/name/<?php echo $row['dirid']; ?>" target="_top"><?php echo $row['directedby']; ?></td>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/name/<?php echo $row['starrid1']; ?>" target="_top"><?php echo $row['starring1']; ?></td>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/name/<?php echo $row['starrid2']; ?>" target="_top"><?php echo $row['starring2']; ?></td>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><?php echo $row['hd']; ?></td>
</tr>
<tr>
<td width="80%" height="38" colspan="4" BORDERCOLOR=white><?php echo $row['filmplot1']; ?></td>
</tr>
<tr>
<td width="80%" height="38" colspan="5" BORDERCOLOR=white><p align="center">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p></td>
</tr>
<?php
}
?>
</table>
<?php
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
}
// end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
}
// end else
}
// end if
}
// end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
}
// end if
/****** end build pagination links ******/
?>
</body>
</html>
Re: cut my page up into more than one page
Although I can't spot any error in the query... Try this
PHP Code:
$id = (isset($_GET['search'])) ? "%" . $_GET["search"] . "%" : "%";
$sql = "SELECT vidnumber, titleid, hd, year,starring1,videotitle,starring2, directedby, filmplot1,dirid,starrid1,starrid2, trilogy,age, Runningtime,WantToWatch FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."' LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
Alternatively you can try this:
PHP Code:
$id = (isset($_GET['search'])) ? "%" . $_GET["search"] . "%" : "%";
$sql = "SELECT * FROM `videolist` WHERE `videotitle` LIKE '".mysql_real_escape_string($id)."' LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
Re: cut my page up into more than one page
hi
still no look with the pagination part.
i did notice at the top of my page there is a total count below
PHP Code:
$sql = "SELECT COUNT(*) FROM videolist";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
should this also include somthing like the select code below
PHP Code:
$id = (isset($_GET['search'])) ? "%" . $_GET["search"] . "%" : "%";
$sql = "SELECT vidnumber, titleid, hd, year,starring1,videotitle,starring2, directedby, filmplot1,dirid,starrid1,starrid2, trilogy,age, Runningtime,WantToWatch FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."' LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
Re: cut my page up into more than one page
the COUNT(*) query should have the same WHERE clause as the other query. because you only define $id later on, move the declaration of $id more near the top of the script.
Re: cut my page up into more than one page
i have now moved it to the top so both searches use it but still having a problem with the page split
PHP Code:
$sql = "SELECT COUNT(*) FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."'";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
i dont think the above bit is working correctly, have i done it right
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>My Videos Site</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>
<div id="mainwrap">
<?php include("header.php"); ?>
<?php include("leftnav.php"); ?>
<div id="contentwrap">
<div id="breadcrumb">
<a href="#">Home</a> :: Main Title Page </div>
<div id="content">
<h2>
</style>
</head>
<table border="1" width="62%" height="126" BORDERCOLOR=white>
<?php
$conn = mysql_connect('localhost','user','userpas') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('vdidb',$conn) or trigger_error("SQL", E_USER_ERROR);
$id = "%".$_GET["search"]."%";
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."'";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 5;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
}
// end if
// if current page is greater than total pages...
if ($currentpage > $totalpages){
// set current page to last page
$currentpage = $totalpages;
}
// end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
}
// end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$sql = "SELECT vidnumber, titleid, hd, year,starring1,videotitle,starring2, directedby, filmplot1,dirid,starrid1,starrid2, trilogy,age, Runningtime,WantToWatch FROM videolist WHERE videotitle LIKE '".mysql_real_escape_string($id)."' LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
// while there are rows to be fetched...
while ($row = mysql_fetch_assoc($result)) {
// <td><?php echo $row['vidnubmer']; ?></td>
<td width="20%" rowspan="4" height="120" BORDERCOLOR=white><p align="center"><img border=0 src="/vidpics/<?php echo $row['videotitle'];?>web.jpg" <?php</p></td>
<td width="20%" height="19" BORDERCOLOR=white><p align="center">ID:<?php echo $row['vidnumber']; ?></td>
<td width="60%" colspan="3" height="19" BORDERCOLOR=white><p align="center"><b><?php echo $row['videotitle']; ?></b></td>
</tr>
<tr>
<td width="20%" height="14" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/title/<?php echo $row['titleid']; ?>" target="_top"><?php echo $row['titleid']; ?></a></td>
<td width="20%" height="14" BORDERCOLOR=white><p align="center">Age <?php echo $row['age']; ?></td>
<td width="20%" height="14" BORDERCOLOR=white><p align="center"><?php echo $row['year']; ?></td>
<td width="20%" height="14" BORDERCOLOR=white><p align="center"><?php echo $row['Runningtime']; ?>mins</td>
</tr>
<tr>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/name/<?php echo $row['dirid']; ?>" target="_top"><?php echo $row['directedby']; ?></td>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/name/<?php echo $row['starrid1']; ?>" target="_top"><?php echo $row['starring1']; ?></td>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><a href="http://imdb.com/name/<?php echo $row['starrid2']; ?>" target="_top"><?php echo $row['starring2']; ?></td>
<td width="20%" height="25" BORDERCOLOR=white><p align="center"><?php echo $row['hd']; ?></td>
</tr>
<tr>
<td width="80%" height="38" colspan="4" BORDERCOLOR=white><?php echo $row['filmplot1']; ?></td>
</tr>
<tr>
<td width="80%" height="38" colspan="5" BORDERCOLOR=white><p align="center">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p></td>
</tr>
<?php
}
?>
</table>
<?php
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
}
// end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
}
// end else
}
// end if
}
// end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
}
// end if
/****** end build pagination links ******/
?>
</body>
</html>
Re: cut my page up into more than one page
what is the actual problem? could you start being a little more descriptive than, "it doesn't work"? does the search function not work? do the page numbers not display correctly? do no records show up at all?
Re: cut my page up into more than one page
hi
sorry kows.
the pages comes up after search looks ok, everything is were it should be and pagination part is at the bottom were i want it. but when i select the next page i get a result from a previous search on the next page and not the result from the current search
for example
i have set pagination part to display 20 records on on each page the first page is ok but if i select the links at the bottom of the page for the next 20 records i get a totaly different result :confused::confused:
Re: cut my page up into more than one page
oh, I understand now. your explanation was off, but I understand what's wrong. your page links are linking to script.php?currentpage=X, where X is the page number, but you're missing the search query after that. so, you'll need to add onto those URLs the search term. first, we should change the search term, though, so that it's URL-safe:
PHP Code:
$searchquery = urlencode($_GET['search']);
then we can insert this query into your pagination links:
PHP Code:
// here's one:
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&search=$searchquery'><</a> ";
// here's another:
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&search=$searchquery'>$x</a> ";
I did two there, but you'll need to add &search=$searchquery to the rest of your links, too.
Re: cut my page up into more than one page
hi
thank you so much kows, i have finished the page to how i want it..
well two weeks ago i didnt know a thing about php, mysql, i have now setup mysql to store all my video collection and view it under a web page. im also working on a vb.net video adder so i can add videos to my collection. thats turnig out tobe interesting aswell. :eek:
thanks again kows :thumb: