This is my PHP code (currently commented out in my templates) which is used in the project mentioned here - http://www.daniweb.com/forums/thread251774.html
(a currently ongoing project):

<div class="indented searchFooter" style="border-top: 1px solid rgb(207, 214, 233);"><table summary="" class="stNoMargins" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="tinyText stNoMargins"><div class="btnContainer"><ul><li><a class="smBtnSel" href="tvguide.php?page=1">1</a></li><li><a class="smBtn" href="tvguide.php?page=2">2</a></li><li><a class="smBtn" href="tvguide.php?page=2" title="Next Page">»</a></li></ul></div></td><td class="smalltext">&nbsp;Total <strong>&raquo;</strong> pages &nbsp;</td></tr></tbody></table>
</div>

I am not sure how to get this working as a pagination script - I tried some scripts from Google but they didn't seem to work.

If I could work out how to get the above output to be auto-generated by PHP, that would be good, but since I'm not sure how to, any advice is appreciated, since I've tried my hand at pagination and it's still hard to learn!

Basically, I am trying to get it to have 20 records per page, so it may mean auto-generating 2 pages, or 3 pages, creating the following URLs (note: these are not "real" URLs, just Apache virtual hosts!):
www.mytvlocalhost.com/tvguide.php?page=1
www.mytvlocalhost.com/tvguide.php?page=2
and so on, where the query string and pagination will appear
(with the pagination in the footer!)

Thanks.

I just wrote a pagination script (for another DaniWeb User). Let me find the link to it and I'll show you my code...

EDIT:
Here's the link:
http://files.phpmycoder.net/1209da

I believe mine does 10 a page, but that is easily fixed. Just read the Readme in the ZIP file and you should find something about changing the items per page. If you can't, you can change the number of results per page by passing the number to the constructor of the pmcPagination class when you create it:

//pmcPagination(resultsPerPage, getVariable, data)
$instance = new pmcPagination(20, "page", new paginationData("test"));

You can also set the results per page by calling the function setResultsPerPage() with the number of results per page as the only parameter.

You can even set this number when calling paginate() the same way as you can when creating the instance of pmcPagination.

The script worked but I got these errors (note that the line numbers here refer to Crimson Editor):
Notice: Undefined variable: resultsPerPage in C:\www\vhosts\mytvguide1.com\pmcPagination.php on line 126

Notice: Undefined variable: resultsPerPage in C:\www\vhosts\mytvguide1.com\pmcPagination.php on line 126

Notice: Undefined variable: pageVar in C:\www\vhosts\mytvguide1.com\pmcPagination.php on line 120

Notice: Undefined variable: resultsPerPage in C:\www\vhosts\mytvguide1.com\pmcPagination.php on line 126

Notice: Undefined variable: resultsPerPage in C:\www\vhosts\mytvguide1.com\pmcPagination.php on line 126

Notice: Undefined variable: pageVar in C:\www\vhosts\mytvguide1.com\pmcPagination.php on line 120

I've had a look through Read Me.txt provided with it but am not sure how to get this working properly.

I'm trying to emulate the effect seen here:
http://library.digiguide.com/lib/programmenextshowing/12578&hPage=1
http://library.digiguide.com/lib/programmenextshowing/12578&hPage=2
(not my website, but an example of how I wanted my pagination script to look!)

Alright, let me look into this. Might just be a little error on my part!

Easy fix! Just a harmless little mix up of function names. Here's the updated version: http://files.phpmycoder.net/1209da/

Thank you for that script, however, this is what I am trying to get it to look like:
http://i46.tinypic.com/2chugs1.jpg
http://i47.tinypic.com/2dr84ky.jpg

(these are based on my current code).

and am not sure how to accomplish this with your code.

I had to put this in your code to get it working when displaying it without the query string in pmcPagination.php:

<?php error_reporting (E_ALL ^ E_NOTICE); ?>

This will fix a bug which happens when you view demo.php as this:
http://localhost/demo.php

without the error_reporting:

Notice: Undefined index: page in C:\www\vhosts\localhost\pmcPagination.php on line 64
Notice: Undefined index: page in C:\www\vhosts\localhost\pmcPagination.php on line 87

(again, using the same text editor referred to earlier in this thread!)

Thank you for your help so far. I am not sure of how to get this to look good now, and show it like the above-linked images.

I have updated the script again to fix the notices (Your setup seems to be very picky about $_GET and $_POST variables!). To achieve what you are looking for, you will need some simple css. With the current code, all you need to do is add this style to the top of your page. The only other thing you will need to do is enclose the navigation inside a div with and id of nav like this:

<div id="nav">
<?php
//Show the navigation
$paginator->navigation();
?>
</div>

And here's the CSS to include:

#nav { font: normal 13px/14px Arial, Helvetica, sans-serif; }
#nav a { background: #EEE; border: 1px solid #DDD; color: #000080; padding: 1px 7px; text-decoration: none; }
#nav strong { background: #000080; border: 1px solid #DDD; color: #FFF; font-weight: normal; padding: 1px 7px; }

The only thing it doesn't do is apply the box (possibly a grayed out one) to the disabled Next and Previous links. If You wish for this to happen, reply back and I'll make the slight changes that are necessary for this to happen.

FlashCreations, I would like your code integrated in, as mentioned above.

This is the code for my data from database being inserted in:

<?PHP
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","PASSWORD");

//select which database you want to edit
mysql_select_db("housemdepisodes");

// Select only results for today and future
$result = mysql_query("SELECT * FROM `epdata` WHERE `expiration`
>=NOW() ORDER BY `expiration` ASC LIMIT 20");

while($r = mysql_fetch_array($result)) {

    $programme   = $r["programme"];
    $channel     = $r["channel"];
    $airdate     = strtotime($r['airdate']);
    $expiration = strtotime($r['expiration']);
    $episode     = $r["episode"];
    $setreminder = $r["setreminder"];
    $now         = time();

    if(date('Y-m-d') == date('Y-m-d', $airdate)) {
        // Same date, show only time
        $dateFormat = 'g:ia';
    } elseif(date('Y') == date('Y', $airdate)) {
        // Same year, show date without year
        $dateFormat = 'F jS - g:ia';
    } else {
        // Other cases, show full date
        $dateFormat = 'F jS, Y - g:ia';
    }

    $airdateFormatted = date($dateFormat, $airdate);

    echo "<tr><td><b>$programme</b></td><td>showing on $channel</td>";
    echo "<td>$airdateFormatted</td><td>$episode</td><td>$setreminder</td></tr>";
}
?>

How do I get the script to include a file from the database, as shown above, and like this:
http://library.digiguide.com/lib/programmenextshowing/Horizon-9595
(which btw, is ASP, not PHP, but where I got the idea from!)
- if there isn't more than one page, the pagination menu doesn't show at all.

Can such a thing be done in PHP?

The existing script is great - will be using it in a project soon, doing some localhost testing work!

Thank you for your help.

One thing at a time...Sure I'd be glad to integrate my pagination class into your code. Give me a few days though, I've jammed two of my fingers and its not too pleasant to type with swollen fingers!
What do you mean: get a script to include a file from the database? The page I see is some TV program guide. Are you trying to include one PHP file in another. If so, try this:

include "file2.php";

I downloaded it, but my WinZip told me it was an empty folder.
Same for 7-Zip... why is this?

Looks like my hosting company has changed some stuff around without me noticing! Sorry about this inconvenience. I can't figure it out right now, but I'll get to it as soon as possible. Hopefully it's an easy fix on my side!

No worries! If it's OK with you, can I redistribute your pagination code from my site, as long as it's credited to you?

As long as credit is given, it is perfectly fine with me! Right now, I'm looking into the downloading problem. It should be fixed soon...

I love your pagination script. But I see it should include notice that you coded it. I understand your concern for your property but I'm curious:
1. Why did you wanted it that way and not free in the meaning of free?
2. If somebody hacked it and derived from it, what should be included.

My Suggestion for you (Just my humble suggestion) is that, for experienced coder like you, should give them away as part of fun! How do you see That?

No offense meant here, just what I see :)

And your absolutely right! I should have just grabbed a Creative Common License, but I didn't (I'm not sure why...). I am planning to do this though. When I complete the update to my site, I will begin to include scripts (like the pagination one) for the use of others. Until then, I don't really have a plan, but hopefully I'll finish my updated site soon!

And your absolutely right! I should have just grabbed a Creative Common License, but I didn't (I'm not sure why...). I am planning to do this though. When I complete the update to my site, I will begin to include scripts (like the pagination one) for the use of others. Until then, I don't really have a plan, but hopefully I'll finish my updated site soon!

So you didn't say what about derived works and in your script it doesn't say. I think it should be given free without any notice (Leaving giving credit to user if he wishes) Like how we do it on Python forum (again that is just MHO). It would be good for PHP moderators to add a stick for sharing codes for those who wish. That is one of the thing that makes Daniweb Python forum the best!

again just my opinions ;)

This is the effect I'm trying to get:
[img]http://i49.tinypic.com/6p3rqa.jpg[/img]
[img]http://i50.tinypic.com/29v0ylx.jpg[/img]

and this is the current page code:

<?php 
include("../header.php");
?>
<?php 
include("epguide1.php");
?>
<?php 
include("footer1.php");
?>

here is the code for epguide1.php:

<?PHP
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","PASSWORD");

//select which database you want to edit
mysql_select_db("housemdepisodes");

// Select only results for today and future
$result = mysql_query("SELECT * FROM `epdata` WHERE `expiration`
>=NOW() ORDER BY `expiration` ASC LIMIT 20");

while($r = mysql_fetch_array($result)) {

    $programme   = $r["programme"];
    $channel     = $r["channel"];
    $airdate     = strtotime($r['airdate']);
    $expiration = strtotime($r['expiration']);
    $episode     = $r["episode"];
    $setreminder = $r["setreminder"];
    $now         = time();

    if(date('Y-m-d') == date('Y-m-d', $airdate)) {
        // Same date, show only time
        $dateFormat = 'g:ia';
    } elseif(date('Y') == date('Y', $airdate)) {
        // Same year, show date without year
        $dateFormat = 'F jS - g:ia';
    } else {
        // Other cases, show full date
        $dateFormat = 'F jS, Y - g:ia';
    }

    $airdateFormatted = date($dateFormat, $airdate);

    echo "<tr><td><b>$programme</b></td><td>showing on $channel</td>";
    echo "<td>$airdateFormatted</td><td>$episode</td><td>$setreminder</td></tr>";
}
?>

I don't know where I should put the pagination script, but I am trying to get it to look like the images above.

Posted in full so people can understand the entire codebase

We know! Sorry for the delay and the problems with my website (As I said, my host has changed the directories around and I can't figure out exactly what they did. I'm submitting a support ticket to them and since their support is excellent I should have a reply in a little less than a day!). In the mean time though, maybe we can arrange something through PM. I can email you the file, if you wish...

It's OK... I just posted it all, for anyone new to the thread, so it's in complete detail!
I was trying some other scripts today, but they seemed a bit complicated for a pagination beginner like me.

Hope the website problems get fixed soon!

(Disclaimer: In accordance with http://www.daniweb.com/forums/announcement17-66.html, this is not a homework help request, but help for a personal project instead!)

Oh alright...my bad. And I also hope that they will be fixed soon (or rather, I hope I can fix them quicker)!

The script works... but one problem, with this bit:

$paginator->add(array(new paginationData("Abc","01",time(),"Soon","1","No"),new paginationData("Def","02",time(),"Soon","1","Yes"),new paginationData("Ghi","03",time(),"Soon","1","Maybe"),new paginationData("Jkl","04",time(),"Sooner","23","Oh Yea!"),new paginationData("Red Sox","13",time(),"Never","1313","Totally!"),new paginationData("Something","03",time(),"?","12?","ugh"),new paginationData("Last One","01",time(),"DOne!","3","no")));

How should I get content from the database in the array, as currently it displays the "No results found on this page" error message despite the code for the database in PmcPagination.php

What code do I need to modify to get it to paginate from the database in demo.php?

Also got these errors:

Notice: Undefined variable: airdate in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: Undefined variable: airdate in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: Undefined property: paginationData::$setreminder in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 169

Notice: Undefined variable: airdate in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: Undefined variable: airdate in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: Undefined property: paginationData::$setreminder in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 169

Notice: Undefined variable: airdate in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: Undefined variable: airdate in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: Undefined property: paginationData:: $setreminder in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 169

Not sure why though... the script otherwise works

Thank you for all your help.

Oh so I see you have found that I fixed the problem! And that line your are referencing is a test line that I used in debug that for some reason came back (My fixes might have altered the file a few times). Let me fix the file (one last time! hopefully) and post back when it's done!

Fixed! This version should be integrated with the code you already provided (That retrieved the results from the DB) and hopefully will work on your server! If you have any questions about the script you can post back here, PM me, or refer to the README file included in the ZIP folder.
http://files.phpmycoder.net/0110dac/

I used the new version... for some reason still got the same errors as above.

Does this code go in demo.php, or am I wrong in thinking this?:

$instance->add(array(new paginationData("test"), new paginationData("test2")));
$instance->add(new paginationData("test3");

I'm not sure how to get it to extract from the database though and show the contents in it.

This is for a client's site, which launches in mid-March.

Thank you for your help - the coding is excellent, been trying the CSS since I downloaded it.

Today's just not a good day for me! The reason you are getting the same errors is because the file on my site wasn't updated. I've tried to upload it several times and for some reason my script is serving an older version. I'll try to upload it again. Sorry for all of these problems!

There! Simple fix! (Try the download again!) The code should be integrated with your database and should request the program info from MySQL just like you did in your first post.

I'm sure you know by now, but just for convenience: http://files.phpmycoder.net/0110dac/

Thank you for integrating the script.
Got this error now:
http://i49.tinypic.com/mipjk1.jpg - warning, large image

(even though the database is correct in the demo.php settings!)

Are you sure you have the correct login credentials. It seems that your password for the root user is not valid.

I fixed the login issue - the login details given were generic php, for security here, as they're different. (basically, I kept private info off here!)

However, it displays "No Results Found" despite the database... please can you update the Read Me.txt to include about SQL usage?

Thank you for this script; I will distribute it if I have your permission to do so, under whatever licence you feel is appropriate.

Also got the following bugs - relating to date/time:

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 167

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 167

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 167

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 167

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 167

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 167

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 160

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 161

Notice: A non well formed numeric value encountered in C:\www\vhosts\mytvguide.com\pmcPagination.php on line 167

The original page [before I used this script] code had this in:

$programme   = $r["programme"];
    $channel     = $r["channel"];
    $airdate     = strtotime($r['airdate']);
    $expiration = strtotime($r['expiration']);
    $episode     = $r["episode"];
    $setreminder = $r["setreminder"];
    $now         = time();
 
    if(date('Y-m-d') == date('Y-m-d', $airdate)) {
        // Same date, show only time
        $dateFormat = 'g:ia';
    } elseif(date('Y') == date('Y', $airdate)) {
        // Same year, show date without year
        $dateFormat = 'F jS - g:ia';
    } else {
        // Other cases, show full date
        $dateFormat = 'F jS, Y - g:ia';
    }
 
    $airdateFormatted = date($dateFormat, $airdate);

but your script has:

class paginationData {
	private $program;
	private $channel;
	private $airdate;
	private $exiration;
	private $episode;
	private $setReminder;
		   
	public function __construct($program, $channel, $airdate, $expiration, $episode, $setReminder)
	{
		$this->program = $program;
		$this->channel = $channel;
		$this->airdate = $airdate;
		$this->expiration = $expiration;
		$this->episode = $episode;
		$this->setReminder = $setReminder;
	}
	
	//This function shows the data
	public function display()
	{
		if(date('Y-m-d') == date('Y-m-d', $this->airdate)) $dateFormat = 'g:ia';
    	elseif(date('Y') == date('Y', $this->airdate)) $dateFormat = 'F jS - g:ia';
		else $dateFormat = 'F jS, Y - g:ia';
	
		echo '<tr>'."\n".
			 '	<td><strong>'.$this->program.'</strong></td>'."\n".
			 '	<td>showing on '.$this->channel.'</td>'."\n".
    		 '	<td>'.date($dateFormat, $this->airdate).'</td>'."\n".
			 '	<td>'.$this->episode.'</td>'."\n".
			 '	<td>'.$this->setReminder.'</td>'."\n".
			 '</tr>'."\n";
	}

This gives the errors mentioned above, plus all date/times as January 1st, 1970 - 1:33am which probably is a bug, I guess.

Hope it's OK, me pointing out the bugs in this.

The script's been good so far, keep up the good work with your site... it looks very promising!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.