Jump to content

Archived

This topic is now archived and is closed to further replies.

DaveLinger

Pagination help

Recommended Posts

here's the code I've got so far... I had more but I cut it off because it wasn't working, but even this shows a blank page:

[code]<html>
<body>
<head>
<link href="resultcss.css" rel="stylesheet" type="text/css" />
</head>
<?php
include('config/file.php');

if($_POST['platform'] == ''){
 
$platform = $_GET['platform'];
$developer = $_GET['developer'];
$publisher = $_GET['publisher'];
$fletter = $_GET['fletter'];
$sortby = $_GET['sort'];
$perpage = $_GET['perpage'];
$order = $_GET['order'];

}else{

$platform = $_POST['platform'];
$developer = $_POST['developer'];
$publisher = $_POST['publisher'];
$fletter = $_POST['fletter'];
$sortby = $_POST['sort'];
$perpage = $_POST['perpage'];
$order = $_POST['order'];

}

if (!$link = mysql_connect($sqlserver, $sqlusername, $sqlpassword)) {
  echo 'Could not connect to mysql';
  exit;
}

if (!mysql_select_db($sqldatabase, $link)) {
  echo 'Could not select database';
  exit;
}

//////////////////////////////////////////////////////////

if($fletter == '%'){
$resource1 = mysql_query('SELECT * FROM nuke_seccont WHERE secid LIKE '$platform' AND developer LIKE '$developer' AND publisher LIKE '$publisher' ORDER BY $sortby $order') or die(mysql_error());
}ELSE{
$resource1 = mysql_query('SELECT * FROM nuke_seccont WHERE secid LIKE '$platform' AND developer LIKE '$developer' AND publisher LIKE '$publisher' AND fletter=$fletter' ORDER BY $sortby $order') or die(mysql_error());
}

$total_results = mysql_result($resource1, 0, 0);

$total_pages = ceil($total_results / $perpage);
$current_page = (isset($_GET['page'])) ? $_GET['page'] : 1;
$current_offset = ($current_page - 1) * $per_page;

echo "total pages: $total_pages<br>current page: $current_page<br>current offset: $current_offset";

}
?>
</body>
</html>[/code]

Here's the rest of the code I had to go after that...

[code]if($fletter == '%'){
$this_page_results = "SELECT * FROM nuke_seccont WHERE secid LIKE '$platform' AND developer LIKE '$developer' AND publisher LIKE '$publisher' ORDER BY $sortby $order LIMIT $current_offset, $perpage";
}ELSE{
$this_page_results = "SELECT * FROM nuke_seccont WHERE secid LIKE '$platform' AND developer LIKE '$developer' AND publisher LIKE '$publisher' AND fletter=$fletter' ORDER BY $sortby $order LIMIT $current_offset, $perpage";
}
$result = mysql_query($this_page_results) or die("Problem with the query: $query<br>" . mysql_error());

mysql_close();

$nextpage = $pagenumber + 1;

echo "<p align=\"right\">Page $current_page of $total_pages <br><a href=\"gosearch.php?page=$nextpage&platform=$platform&developer=$developer&publisher=$publisher&fletter=$fletter&sortby=$sort&perpage=$perpage&order=$order\">Next Page</a></p>Search successful! $numberofresults results found.";

$i=0;
while ($i < $perpage) {

$artid=mysql_result($result,$i,"artid");
$secid=mysql_result($result,$i,"secid");
$title=mysql_result($result,$i,"title");
$counter=mysql_result($result,$i,"counter");
$score6=mysql_result($result,$i,"score6");

echo "<p>● <a href=\"review.php?artid=$artid\" title=\"$title's final score is $score6. It has $counter hits\" target=\"_parent\"><b>$title</b></a><p>";

$i++;
}[/code]

Share this post


Link to post
Share on other sites
If you want to enclose variables in single quotes, then you either need to use double quotes for the query string or escape the single quotes. Also, <head> cannot come after <body>. Try this:

[code]<html>
<head>
<link href="resultcss.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
include('config/file.php');

if($_POST['platform'] == ''){
 
$platform = $_GET['platform'];
$developer = $_GET['developer'];
$publisher = $_GET['publisher'];
$fletter = $_GET['fletter'];
$sortby = $_GET['sort'];
$perpage = $_GET['perpage'];
$order = $_GET['order'];

}else{

$platform = $_POST['platform'];
$developer = $_POST['developer'];
$publisher = $_POST['publisher'];
$fletter = $_POST['fletter'];
$sortby = $_POST['sort'];
$perpage = $_POST['perpage'];
$order = $_POST['order'];

}

if (!$link = mysql_connect($sqlserver, $sqlusername, $sqlpassword)) {
  echo 'Could not connect to mysql';
  exit;
}

if (!mysql_select_db($sqldatabase, $link)) {
  echo 'Could not select database';
  exit;
}

//////////////////////////////////////////////////////////

if($fletter == '%'){
$resource1 = mysql_query("SELECT * FROM nuke_seccont WHERE secid LIKE '$platform' AND developer LIKE '$developer' AND publisher LIKE '$publisher' ORDER BY " . $sortby . " " . $order) or die(mysql_error());
}ELSE{
$resource1 = mysql_query("SELECT * FROM nuke_seccont WHERE secid LIKE '$platform' AND developer LIKE '$developer' AND publisher LIKE '$publisher' AND fletter='$fletter' ORDER BY " . $sortby . " " . $order) or die(mysql_error());
}

$total_results = mysql_result($resource1, 0, 0);

$total_pages = ceil($total_results / $perpage);
$current_page = (isset($_GET['page'])) ? $_GET['page'] : 1;
$current_offset = ($current_page - 1) * $per_page;

echo "total pages: $total_pages<br>current page: $current_page<br>current offset: $current_offset";

}
?>
</body>
</html>[/code]

The rest of the code that you have after that should be fine.

Share this post


Link to post
Share on other sites

×

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.