|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
PHP Question
I am currently working on a news posting script for my team's site using PHP. I've got everything down for posting and adding news, but I need a way to have only the most recent posts added. I tried to create a while loop so that only the 5 most recent posts show on the index page, but it didn't work. If anyone can help me figure it out, help would be greatly appreciated. And i simplified the part of the code that displays the post.
PHP Code:
|
|
#2
|
||||
|
||||
|
Re: PHP Question
I'm not sure exactly how your code was intended to work, but it appears that you check each line of news.tct for "|" which are used to divide that line into two parts ($pieces[0] and [1]) that are then just outputted concatenatedly so the output is just the text without the pipes. I think maybe you intended "|" to seperate different entires but you didn't realize that file() reads each line into a new element in the array.
|
|
#3
|
|||||
|
|||||
|
Re: PHP Question
Quote:
If not, then why not just write the newest news information at the top of the file? I believe there's a way to set the file pointer to the beginning of the file before you write. (I can't supply code for doing the file stuff...I've had issues with doing that in the past) |
|
#4
|
|||||
|
|||||
|
Re: PHP Question
Quote:
Date|Poster's Name|News Title|News Story And yes, the | is used to separate each section. Quote:
|
|
#5
|
|||||
|
|||||
|
Re: PHP Question
Quote:
PHP Code:
|
|
#6
|
|||||
|
|||||
|
Re: PHP Question
Quote:
EDIT: I've got it, rudimentary as it is: PHP Code:
Last edited by Joshua May : 11-06-2004 at 16:53. |
|
#7
|
|||||
|
|||||
|
Re: PHP Question
Now I have a new question. I have set up a user authentication page, which asks for a username and password. If the correct username and password are given, I want the browser to redirect to a certain page. Hwoever, I don't know the PHP function (if there is one) that will redirect to a new page. I've searched around but I can't find anything.
|
|
#8
|
|||||
|
|||||
|
Re: PHP Question
Quote:
PHP Code:
$user = $_POST['username']; - stores the entered username (in the textbox) into a variable. username is the name of the textbox. $pass = $_POST['password']; - same as above, but subtitute the obvious. The reason for having the if(...) case above the <HTML> tag is because since <HTML> is a header, you can't send a header after a another header (it's hard for me to explain, so just look up the "header()" function in the PHP doc.). Your form should look something like this (assuming the form is located on a page called: "login_admin.php"): <form action="login_admin.php" method="POST"> <input type=text name=username><br> <input type=password name=password><br> <input type=submit name=login value="Login"> </form> |
|
#9
|
|||||
|
|||||
|
Re: PHP Question
Thanks Raven_Writer, for all your help.
![]() |
|
#10
|
|||||
|
|||||
|
Re: PHP Question
Quote:
I've been doing this kinda thing so many times, I've got it all memorized. lol. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PHP Question | Raven_Writer | Website Design/Showcase | 2 | 22-05-2004 18:42 |
| Question of the Week [05-02-04]: The Very Merry Month of May | EddieMcD | Rumor Mill | 10 | 05-05-2004 14:02 |
| A question about control system options | computhief263 | Control System | 7 | 04-02-2004 14:46 |
| What's better, PERL/cgi or PHP/my_sql? | mikefrei | Programming | 10 | 27-05-2002 22:50 |