Go to Post A FIRST fanatic who never had any desire to be an engineer. There. I said it. ;) - Katie Reynolds [more]
Home
Go Back   Chief Delphi > Technical > IT / Communications > Website Design/Showcase
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 10-06-2004, 18:32
Joshua May's Avatar
Joshua May Joshua May is offline
Go Bears!
FRC #1110 (Binary Bulldogs)
Team Role: College Student
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Berkeley, CA
Posts: 1,306
Joshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond repute
Send a message via AIM to Joshua May
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:
<?
$data 
file('news.txt');
$data array_reverse($data);
foreach(
$data as $element) {
    
$element trim($element);
    
$pieces explode("|"$element);
    echo 
$pieces[0] . $pieces[1] . "\n";
    echo 
"<hr>\n";
}
?>
__________________
The FIRST Wiki - openFIRST - Ultimate Robot Challenge - URC Wiki
I currently have 50 GMail invites, PM or email me for one.
UC Berkeley Class of 2009

2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed
  #2   Spotlight this post!  
Unread 10-06-2004, 19:07
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
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.
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #3   Spotlight this post!  
Unread 10-06-2004, 19:52
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: PHP Question

Quote:
Originally Posted by HHSJosh
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.

...
If at all possible, would you be able to use a database like MySQL?

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)
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #4   Spotlight this post!  
Unread 11-06-2004, 15:42
Joshua May's Avatar
Joshua May Joshua May is offline
Go Bears!
FRC #1110 (Binary Bulldogs)
Team Role: College Student
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Berkeley, CA
Posts: 1,306
Joshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond repute
Send a message via AIM to Joshua May
Re: PHP Question

Quote:
Originally Posted by maxoblovsky
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.
Sorry that I didn't elaborate on that, the file news.txt which contains all of the news looks like this:

Date|Poster's Name|News Title|News Story

And yes, the | is used to separate each section.

Quote:
Originally Posted by Raven_Writer
If at all possible, would you be able to use a database like MySQL?

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)
I do have access to three MYSQL databases, but I haven't yet learned how to interface with MYSQL yet. Also, I use the array_reverse() function to read the newest news from the top of the file, I just need some way where I can just get the newest five stories to display.
__________________
The FIRST Wiki - openFIRST - Ultimate Robot Challenge - URC Wiki
I currently have 50 GMail invites, PM or email me for one.
UC Berkeley Class of 2009

2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed
  #5   Spotlight this post!  
Unread 11-06-2004, 15:49
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: PHP Question

Quote:
Originally Posted by HHSJosh
I do have access to three MYSQL databases, but I haven't yet learned how to interface with MYSQL yet. Also, I use the array_reverse() function to read the newest news from the top of the file, I just need some way where I can just get the newest five stories to display.
Hm...maybe seperate each item by underscores or something, and scan the file for it, and each time it's found, fill an array w/ the info and also use a counter. An example:
PHP Code:
// number of news items read
$num_news 0;
 
// global array defined here
 
// open file for reading
$file fopen("news.txt""r");
 
// read file
$stuff fread($file);
 
// loop through the reading
while(($num_news 5) && ($stuff != eof())){
/* store news items in an array...I'm not sure on howto do this, so... */

__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #6   Spotlight this post!  
Unread 11-06-2004, 16:25
Joshua May's Avatar
Joshua May Joshua May is offline
Go Bears!
FRC #1110 (Binary Bulldogs)
Team Role: College Student
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Berkeley, CA
Posts: 1,306
Joshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond repute
Send a message via AIM to Joshua May
Re: PHP Question

Quote:
Originally Posted by Raven_Writer
Hm...maybe seperate each item by underscores or something, and scan the file for it, and each time it's found, fill an array w/ the info and also use a counter. An example:
Thanks, I'll try that, really the while(($num_news < 5) && ($stuff != eof())) is what I was looking for, just not really sure where to put it in the code.

EDIT: I've got it, rudimentary as it is:
PHP Code:
<?
$counter 
0;
$data file('news.txt');
$data array_reverse($data);
foreach(
$data as $element)
{
if(
$counter 5)
  {
      
$element trim($element);
      
$pieces explode("|"$element);
      echo 
$pieces[0] . $pieces[1] . $pieces[2] . $pieces[3];
      echo 
"<hr>\n";
  }
else
  {
  }
$counter $counter 1;
}
?>
__________________
The FIRST Wiki - openFIRST - Ultimate Robot Challenge - URC Wiki
I currently have 50 GMail invites, PM or email me for one.
UC Berkeley Class of 2009

2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed

Last edited by Joshua May : 11-06-2004 at 16:53.
  #7   Spotlight this post!  
Unread 11-06-2004, 20:37
Joshua May's Avatar
Joshua May Joshua May is offline
Go Bears!
FRC #1110 (Binary Bulldogs)
Team Role: College Student
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Berkeley, CA
Posts: 1,306
Joshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond repute
Send a message via AIM to Joshua May
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.
__________________
The FIRST Wiki - openFIRST - Ultimate Robot Challenge - URC Wiki
I currently have 50 GMail invites, PM or email me for one.
UC Berkeley Class of 2009

2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed
  #8   Spotlight this post!  
Unread 11-06-2004, 20:46
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: PHP Question

Quote:
Originally Posted by HHSJosh
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.
Here's some code to do it:

PHP Code:
// ** BELOW CODE ABOVE THE <HTML> TAG!! **
$log $_POST['login'];
 
$user $_POST['username'];
$pass $_POST['password'];
 
if((
$log) && ($user == /* stored username */) && ($pass == /* stored password */)){
  
header('Location: http://the.address.to.the.redirection.com');
} else{
  
// login script

$log = $_POST['login']; - this is storing the value of "login" in a variable "$login". login is the name of the submit button of the form.

$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>
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #9   Spotlight this post!  
Unread 11-06-2004, 20:49
Joshua May's Avatar
Joshua May Joshua May is offline
Go Bears!
FRC #1110 (Binary Bulldogs)
Team Role: College Student
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Berkeley, CA
Posts: 1,306
Joshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond repute
Send a message via AIM to Joshua May
Re: PHP Question

Thanks Raven_Writer, for all your help.
__________________
The FIRST Wiki - openFIRST - Ultimate Robot Challenge - URC Wiki
I currently have 50 GMail invites, PM or email me for one.
UC Berkeley Class of 2009

2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed
  #10   Spotlight this post!  
Unread 11-06-2004, 20:50
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: PHP Question

Quote:
Originally Posted by HHSJosh
Thanks Raven_Writer, for all your help.
No problemo.

I've been doing this kinda thing so many times, I've got it all memorized. lol.
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 00:27.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi