944,068 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3762
  • PHP RSS
Jun 29th, 2005
0

Auto Addition Script

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
4BoredomDotCom is offline Offline
9 posts
since Mar 2005
Jun 29th, 2005
0

Re: Auto Addition Script

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.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: error message with sessions
Next Thread in PHP Forum Timeline: php.ini file not being read





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC