I am trying to make a joke site..... I havent dont the rating system yet but have one previous issue to deal with and cant find it in any of my books.

I want to have a password protected admin page, addjoke.php where I can add by category like "Blonde Jokes" or "President Bush Jokes". I know how to make a form write to a different page, which is beginner php, but how do I have it be incremented 0001.php and up which will go up each time I add one, and still be placed in its specific category. This is probably simple, I dont neccessarily need an answer but if someone can point me in the right direction it would be greatly appreciated.

11 Years
Discussion Span
Last Post by Troy

It sounds like you plan to have each joke be it's own PHP page?

Joke #1: 0001.php
Joke #2: 0002.php
Joke #3: 0003.php

That will work, but considering that each joke is only a small bit of text, and that you probably have a lot of other common stuff on each page, you probably should consider storing the jokes in a database. If you don't want to deal with a database yet, you could store the jokes in simple text files that you then include within the "joke" page.

To address your question of how to build the numerically ascending filenames, first realize that you will need some mechanism to "remember" the last number in the sequence. This could be done a number of ways (no pun intended). If you store each joke in a text file named like 0001.txt, 0002.txt, 0003.txt, there are ways to retrieve the "highest" filename from the directory, break the filename apart (check out basename() or pathinfo() functions), then increase it by one and pad with zeros (check out str_pad()) to build your new filename. Probably a better method is to store your jokes in a database and simply use an autonumber id to maintain a unique index.

With either of these techniques, you would use a single page (perhaps joke.php). You'd pass a joke ID to the script, and it would return the joke. e.g. joke.php?id=145. joke.php would have code to either include the joke text file or retrieve the joke text from the database.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.