Link to home
Start Free TrialLog in
Avatar of AhmadKhatib
AhmadKhatib

asked on

Creating PHP Pages on the fly

Hello, once again,
On the same subject as all my questions, here is the example, http://www.flashfx.net/gta2online.

Ok, what I want to do is, if you look at the front page, I have a game already added called Testing Game thats irrelevant though. What I want is that when the amount of added games reaches; lets say 10, to create a second page on the fly with the newer games pushing the older games onto that page. Then of course when the second page reaches 10 to make a third and so on. I want it as simple as possible. However, since i'm not too too familiar with PHP im making the Q worth 50 points, but if this turns out to be complicated Ill increase so not to be cheap.
Avatar of Big_Red_Dog
Big_Red_Dog

If these are coming from a database, then why do you need more than 1 PHP page?  You create a page that pulls out the first 10 from the database, then you provide a link "NEXT" that is a link the the same PHP file only with a hint in the query_string as to what to do.

So if the PHP file is foo.php, if it is called with no query string, pull the first 10.  On that page, have a link "NEXT" that is the url foo.php?start=11 if this link is clicked, then you see that start=11 and you pull 11-20 from the database and this time you have a next and previous link, one is foo.php?start=1 and the other is foo.php?start=21 (if there are more than 20 that is).

first of all, you will need two thing:

1. variable $from passed in GET which will be the number of the page (ie: 1 for the first page, 2 for the second etc)

2. static variable in the PHP file for $offset (the amount of records to display - in your case 10)


Solutions are two as well:

1) Define the number of the initial record:

$offset * ($from-1)

so, for the first page this will be: 10 * (1 - 1) which is 0 so we start from record 0 and for the second this will be 10 and for the third this will be 20 and so on.


2. Retrieve the results:

1. if the list is coming from the DB:

   do:

SELECT * FROM table WHERE this=that LIMIT $from+1, $offset;

 This will returnyou `$offset' rows starting from the row number `$from'.


2. if the staff is within an array defined some other way:

   do:

for($i=$from; $i<($from+$offset); $i++) {
   ...
}


Now, you might need to slightly adjust this code, but it should clearly explain you the solution.


NOTE: LIMIT is for mySQL, some other DBs have other SQL syntax. For instance, in Oracl this would be ...WHERE rownum between($from, ($from+$offset)) but this might be irrelevant for you.

Cheers,
Maxim Maletsky
maxim@php.net
Avatar of AhmadKhatib

ASKER

hmmm, big red dog... can you give a simple example of how to make it so that the page will understand how to do  foo.php?start=1 ? I have notices in many sites where the link is lets say index.php?jump=5342 or something like that. i like your solution but how does that work?
hmmm, big red dog... can you give a simple example of how to make it so that the page will understand how to do  foo.php?start=1 ? I have notices in many sites where the link is lets say index.php?jump=5342 or something like that. i like your solution but how does that work?
Hi,  I will post to this soon.  The EE notifications were broken, so I didn't get this until now and I have a meeting tonight, so I'll respond soon.  Sorry for the delay
no problem.
ASKER CERTIFIED SOLUTION
Avatar of Big_Red_Dog
Big_Red_Dog

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the table is updated while someone is doing prev and next, their pages will change as well, so if they are browsing 100 items, and another is added, they will start to browse all 101 on the next selection of NEXT or PREV which means that it is possible to do a NEXT and then a PREV and the PREV page might be different depending on where the new record is added.