• Help
  • Search
  • Login
  • Register
  • Home

Forum: web design and graphics community

Celestial Star Forum > Web Development > Coding > paging problems
Pages: [1]
« previous next »
  Print  
Author Topic: paging problems  (Read 1209 times)
Rosie870
Angeling
*
Posts: 8


View Profile
paging problems
« on: January 24, 2008, 11:22:26 PM »


nevermind I have fixed the download counter problems...

the only problem left is the pages. When clicked they won't go to the next page instead they go to the homepage.

Code:
<?php
$hostname 
= ""; 
$user = ""; 
$pass = "";
$dbname = ""; 
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbname , $connection) or die ("Cannot select db");

$q="SELECT * from png order by id desc";
$result= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());


$rows_per_page=5;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);

if (!isset(
$screen))
$screen=0;
$start = $screen * $rows_per_page;
$q= "select * from png order by id desc LIMIT $start,
$rows_per_page"
;
$re= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());


// Continue usual Code, display data
$c = 0;
echo 
"
<p align=\"center\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"90%\"><tr><td> </td></tr> <tr>
"
;  
 
while (
$r = mysql_fetch_array($re))
{
$id=$r["id"];
$series=$r["series"];
$features=$r["features"];
$designer=$r["designer"];
$date=$r["date"];
$download=$r["download"];
$downloaded=$r["downloaded"];
$image=$r["image"];
if (
$c == 0)
echo 
" 
<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded  </li>
</ul>
</div>
</td>


"
;

elseif (
$c == 1)
echo 
"

<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded  </li>
</ul>
</div>
</td><tr></tr>
"
;

$c++;
$c = $c%2;
} 
 
echo
"</table><br />";


if (
$screen > 0) {
$j = $screen - 1;
$url = "$PHP_SELF?page=$j";
echo 
"<a href=\"$url\">&laquo; Prev</a>";
}

// page numbering links now

for ($i = 0; $i < $pages; $i++) {
$url = "$PHP_SELF?page=" . $i;
$j = $i + 1;
echo 
" | <a href=\"$url\">$j</a> | ";
}

if (
$screen < $pages-1) {
$j = $screen + 1;
$url = "$PHP_SELF?page=$j";
echo 
"<a href=\"$url\">Next &raquo;</a>";
}


?>
« Last Edit: January 25, 2008, 09:39:43 PM by Rosie870 » Logged
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: paging problems
« Reply #1 on: January 25, 2008, 11:32:17 PM »

Try replacing this code:

Quote
$rows_per_page=5;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);

if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$q= "select * from png order by id desc LIMIT $start,
$rows_per_page";
$re= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

// Continue usual Code, display data
$c = 0;
echo

with this code:

Quote
$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];

$rows_per_page=5;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);

if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$query .= "LIMIT $start, $rows_per_page";
$result= mysql_query($query) or die
("Could not execute query : $query." . mysql_error());

// Continue usual Code, display data
$c = 0;
echo

Not sure if that will work, since your code is slightly different from my own, but here's to lady luck.
Logged

Rosie870
Angeling
*
Posts: 8


View Profile
Re: paging problems
« Reply #2 on: January 25, 2008, 11:44:34 PM »

It didn't work  Annoyed I got this error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/rosie870/public_html/transparent.php on line 43
« Last Edit: January 25, 2008, 11:47:34 PM by Rosie870 » Logged
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: paging problems
« Reply #3 on: January 26, 2008, 01:18:37 AM »

Sorry, just noticed a lot of things I missed.  First, since your code abbreviates, let's change this code:

Quote
$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];

$rows_per_page=5;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);

if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$query .= "LIMIT $start, $rows_per_page";
$result= mysql_query($query) or die
("Could not execute query : $query." . mysql_error());

// Continue usual Code, display data
$c = 0;
echo

to this (to reflect the abbreviation for query):

Code:
$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];

$rows_per_page=5;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);

if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$q .= "LIMIT $start, $rows_per_page";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

// Continue usual Code, display data
$c = 0;
echo

Then, go down to the page numbering and change this:

Quote
for ($i = 0; $i < $pages; $i++) {
$url = "$PHP_SELF?page=" . $i;
$j = $i + 1;
echo " | <a href=\"$url\">$j</a> | ";

to this (which now reflects using $c instead of $i):

Code:
for ($c = 0; $c < $pages; $c++) {
$url = "$PHP_SELF?page=" . $c;
$j = $c + 1;
echo " | <a href=\"$url\">$j</a> | ";

If that's doesn't work, I'm gonna try an overhaul on the code.
Logged

Rosie870
Angeling
*
Posts: 8


View Profile
Re: paging problems
« Reply #4 on: January 26, 2008, 08:43:07 PM »

I tried it the way you gave me and I got the following error:

Code:
Could not execute query : SELECT * from png order by id descLIMIT 0, 2.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'descLIMIT 0, 2' at line 1


So I tried it like this:

Code:
<?php
$hostname 
= ""; 
$user = ""; 
$pass = "";
$dbname = ""; 
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbname , $connection) or die ("Cannot select db");

$q="SELECT * from png order by id desc";
$result= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());

$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];

$rows_per_page=2;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);

if (!isset(
$screen))
$screen=0;
$start = $screen * $rows_per_page;
$q= "select * from png order by id desc LIMIT $start,$rows_per_page";
$re= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());

// Continue usual Code, display data
$c = 0;

// Continue usual Code, display data
$c = 0;
echo 
"
<p align=\"center\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"90%\"><tr><td> </td></tr> <tr>
"
;  
 
while (
$r = mysql_fetch_array($re))
{
$id=$r["id"];
$series=$r["series"];
$features=$r["features"];
$designer=$r["designer"];
$date=$r["date"];
$download=$r["download"];
$downloaded=$r["downloaded"];
$image=$r["image"];
if (
$c == 0)
echo 
" 
<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded  </li>
</ul>
</div>
</td>


"
;

elseif (
$c == 1)
echo 
"

<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded  </li>
</ul>
</div>
</td><tr></tr>
"
;

$c++;
$c = $c%2;
} 
 
echo
"</table><br />";


if (
$screen > 0) {
$j = $screen - 1;
$url = "$PHP_SELF?page=$j";
echo 
"<a href=\"$url\">&laquo; Prev</a>";
}

// page numbering links now

for ($c = 0; $c < $pages; $c++) {
$url = "$PHP_SELF?page=" . $c;
$j = $c + 1;
echo 
" | <a href=\"$url\">$j</a> | ";
}

if (
$screen < $pages-1) {
$j = $screen + 1;
$url = "$PHP_SELF?page=$j";
echo 
"<a href=\"$url\">Next &raquo;</a>";
}


?>

And while now it does give me the page url like this transparent.php?page=2 when I click on the next page it still shows the same page,
Logged
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: paging problems
« Reply #5 on: January 27, 2008, 12:54:42 PM »

You have a lot of inconsistencies by using the abbreviation $re for result instead of the full version $result which is used in the beginning part of the code.  Also, you're repeating this line:

Quote
// Continue usual Code, display data
$c = 0;

The specific extraction of the rows is unnecessary, and can easily be replaced by this code (I changed the abbreviation of row to the full text for clarity):

Code:
extract($row);

Also, some of your quotations were meant to be apostrophes.  So here's the final coding which I came up with:

Code:
<?php
$hostname 
= ""; 
$user = ""; 
$pass = "";
$dbname = ""; 
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbname , $connection) or die ("Cannot select db");

$q="SELECT * from png order by id desc";
$result= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());

$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];

$rows_per_page=2;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);

if (!isset(
$screen))
$screen=0;
$start = $screen * $rows_per_page;
$q= "LIMIT $start,$rows_per_page";
$result= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());

// Continue usual Code, display data
$c = 0;

echo 
'
<p align=\"center\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"90%\"><tr><td> </td></tr> <tr>
'
;  
 
while (
$row = mysql_fetch_array($result))
{
extract($row);

if (
$c == 0)
{
echo 
" 
<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded  </li>
</ul>
</div>
</td>
"
;
}

else
{
echo 
"

<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded  </li>
</ul>
</div>
</td><tr></tr>
"
;
}

$c++;
$c = $c%2;
} 
 
echo
'</table><br />';


if (
$screen > 0) {
$j = $screen - 1;
$url = "$PHP_SELF?page=$j";
echo 
"<a href=\"$url\">&laquo; Prev</a>";
}

// page numbering links now

for ($c = 0; $c < $pages; $c++) {
$url = "$PHP_SELF?page=" . $c;
$j = $c + 1;
echo 
" | <a href=\"$url\">$j</a> | ";
}

if (
$screen < $pages-1) {
$j = $screen + 1;
$url = "$PHP_SELF?page=$j";
echo 
"<a href=\"$url\">Next &raquo;</a>";
}

?>
Logged

Rosie870
Angeling
*
Posts: 8


View Profile
Re: paging problems
« Reply #6 on: January 27, 2008, 03:57:15 PM »

I am still getting the following error

Could not execute query : LIMIT 0,2.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0,2' at line 1
Logged
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: paging problems
« Reply #7 on: January 27, 2008, 05:29:19 PM »

Change this code:

Quote
$q= "LIMIT $start,$rows_per_page";

to this:

Quote
$q .= "LIMIT $start, $rows_per_page";

and it should work.  It works just fine for my own database.
Logged

Rosie870
Angeling
*
Posts: 8


View Profile
Re: paging problems
« Reply #8 on: January 27, 2008, 05:38:32 PM »


I am still getting the same error as before.

Could not execute query : SELECT * from png order by id descLIMIT 0, 2.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'descLIMIT 0, 2' at line 1

It has something to do with this part

Code:
if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$q .= "LIMIT $start, $rows_per_page";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

because when changed to

Code:
if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$q= "select * from png order by id desc LIMIT $start,
$rows_per_page";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

the page shows but the navigation just doesn't work
Logged
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: paging problems
« Reply #9 on: January 27, 2008, 06:42:17 PM »

The reason I keep changing this part of the code:

Quote
$q= "select * from png order by id desc LIMIT $start,
$rows_per_page";

to this:

Quote
$q .= "LIMIT $start, $rows_per_page";

is to avoid the repetitive page.  The problem is actually much higher than where the code is complaining (a typical reaction for php).  Change this piece of code:

Quote
$q="SELECT * from png order by id desc";

to this:

Code:
$q="SELECT * from png order by id desc ";

The only difference between the two pieces of code is the single space after the "desc" command, a common error in php.
Logged

Rosie870
Angeling
*
Posts: 8


View Profile
Re: paging problems
« Reply #10 on: January 27, 2008, 07:40:59 PM »

Ah. I understand now and have changed it. Now the page appears but the paging still does not work.

Here is the coding as of now:

Code:
<?php
$hostname 
= ""; 
$user = ""; 
$pass = "";
$dbname = ""; 
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbname , $connection) or die ("Cannot select db");

$q="SELECT * from png order by id desc ";
$result= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());

$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];

$rows_per_page=2;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);

if (!isset(
$screen))
$screen=0;
$start = $screen * $rows_per_page;
$q .= "LIMIT $start, $rows_per_page";
$result= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());

// Continue usual Code, display data
$c = 0;

echo 
'
<p align=\"center\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"90%\"><tr><td> </td></tr> <tr>
'
;  
 
while (
$row = mysql_fetch_array($result))
{
extract($row);

if (
$c == 0)
{
echo 
" 
<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded  </li>
</ul>
</div>
</td>
"
;
}

else
{
echo 
"

<td class=\"outline\">
<div id=\"st\">
<center><img src=\"$image\" class=\"button\" width=\"125\" height=\"100\" alt=\"$id\"></center>
<ul>
<li> <strong>date</strong>: $date </li>
<li> <a target=\"_new\" href=\"pngdownload.php?id=$id\"><strong>Download</strong></a>: $downloaded  </li>
</ul>
</div>
</td><tr></tr>
"
;
}

$c++;
$c = $c%2;
} 
 
echo
'</table><br />';


if (
$screen > 0) {
$j = $screen - 1;
$url = "$PHP_SELF?page=$j";
echo 
"<a href=\"$url\">&laquo; Prev</a>";
}

// page numbering links now

for ($c = 0; $c < $pages; $c++) {
$url = "$PHP_SELF?page=" . $c;
$j = $c + 1;
echo 
" | <a href=\"$url\">$j</a> | ";
}

if (
$screen < $pages-1) {
$j = $screen + 1;
$url = "$PHP_SELF?page=$j";
echo 
"<a href=\"$url\">Next &raquo;</a>";
}

?>
Logged
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: paging problems
« Reply #11 on: January 27, 2008, 07:59:25 PM »

Your pagination script was telling the next pages to proceed to "$PHP_SELF?page" instead of the correct "$PHP_SELF?screen."

Here's the working code for the pagination script:

Code:
if ($screen > 0) {
$j = $screen - 1;
$url = "$PHP_SELF?screen=$j";
echo "<a href=\"$url\">Prev</a> | ";
}

// page numbering links now

for ($c = 0; $c < $pages; $c++) {
$url = "$PHP_SELF?screen=" . $c;
$j = $c + 1;
echo " <a href=\"$url\">[$j]</a> | ";
}

if ($screen < $pages-1) {
$j = $screen + 1;
$url = "$PHP_SELF?screen=$j";
echo "<a href=\"$url\">Next</a>";
}

For curiosity's sake, where did you get this code?
Logged

Rosie870
Angeling
*
Posts: 8


View Profile
Re: paging problems
« Reply #12 on: January 27, 2008, 08:21:28 PM »

Oh lord it actually works  Smiley I can't stop thanking you enough for taking so much time to help me out.

As for the coding... an ex-friend of mine coded it for me years ago  Annoyed  it actually worked just fine back then.

Anyway thank you so very much. Though now I am getting a line error on my download page saying:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/rosie870/public_html/pngdownload.php on line 13

Here is the coding:
Code:
<?php
$hostname 
= ""; 
$user = ""; 
$pass = "";
$dbname = ""; 
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbname , $connection) or die ("Cannot select db");
$id = $_GET['id'];
$q="SELECT * from png where id='$id'";
$result= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());
while (
$r=mysql_fetch_array($result))
{
$id=$r["id"];
$series=$r["series"];
$features=$r["features"];
$designer=$r["designer"];
$date=$r["date"];
$download=$r["download"];
$downloaded=$r["downloaded"];
$image=$r["image"];
echo 
" 
<table border=\"0\" align=\"center\">
<tr>
<td>
<img class=\"outline\" vspace=\"10\" hspace=\"10\" border=\"0\" src=\"$download\" alt=\"$id\" \> <br>
<strong>Date:</strong>  $date <br>
<strong>Series:</strong> $series <br>
<strong>Downloads:</strong> $downloaded
</tr>
</td>
</table>
"
;
$q="update png set downloaded=downloaded+1 where id='$id'";
$result= mysql_query($q) or die
(
"Could not execute query : $q." . mysql_error());
}
?>
Logged
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: paging problems
« Reply #13 on: January 27, 2008, 11:21:30 PM »

To tell you the truth, I've never seen a page which combined both the download and the actual viewed information (such as your table) together on one page.  The download requires two pages, and it could be the page isn't working because you can't combine the separate information.  Melfina has a good tutorial on how to do the download counter, which is almost exactly like your code, at this location.  There is also the DayDream Graphics tutorial on the same subject here.

I myself go by a form which I can't recall the website, and that code is different from the two tutorials I already mentioned above.  I hope these links help you.
Logged

Pages: [1]
  Print  
« previous next »
 
Jump to:  

  • Welcome, Guest
  • Members login
  • Register for free

General

  • General
  • New members
  • Announcements
  • Support / Suggestions

Art boards

  • Creative mediums
  • Requests and offers
  • Tutorials
  • Celestial Star tutorials

Web development

  • Coding
  • Web design
  • Advertisements / affiliation

Off-topic

  • The non-sense
  • Ententainment

Go up
eXTReMe Tracker
  • Valid XHTML
  • Valid CSS
Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC | Seo4Smf v0.2 © Webmaster's Talks
Loading...