Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 2nd, 2002, 09:08 PM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
I updated Matt's News Feed, but...

I just updated Matt's news feed, but I'm having a problem. My requirements say I CANNOT use a database, so I'm going with flat text files. I only want to display the 5 most recent entires on the front page. The system is completely functional, but I don't like the way I'm getting the five posts. I've included, the code below, but the site can be seen and tried at http://firsttube.com/build - the password is "password" without quotes.

Can someone help me come up with something better than a session var to do this?

-Adam

php Code:
Original - php Code
  1.  
  2. <?php
  3. // create a new session
  4. // register a session-variable
  5. session_register("newslimit");
  6. // Assign a value to the session-variable
  7. $newslimit = "0";
  8. //news archive
  9. $archive = "allnews.php";
  10. ?>
  11. <html>
  12. <center>
  13.  
  14. <a href="admin.php"><font face=tahoma size=2>to admin</font></a><p>
  15. <table width=640>
  16. <?php
  17.  
  18.     $display = (str_replace("_"," ",$author));
  19.     echo "<TR><TH align=center bgcolor=#003366><font face=tahoma color=#c0c0c0 size=2>";
  20.     echo "Last 5 items submitted <a href=allnews.php>";
  21.     echo "<font color=white>(view news archive)</font></a>";
  22.     echo "</TH></TR>";
  23.  
  24. $data = file("news.txt");
  25. $data = array_reverse($data);
  26. foreach($data as $element) {
  27.     $element = trim($element);
  28.     $slashpieces = explode("|", $element);
  29.     $pieces[0] = stripslashes($slashpieces[0]);
  30.     $pieces[1] = stripslashes($slashpieces[1]);
  31.     $pieces[2] = stripslashes($slashpieces[2]);
  32.     $pieces[3] = stripslashes($slashpieces[3]);
  33.     $fullname = (str_replace(" ","_",$pieces[1]));
  34. if ($newslimit < 5) {
  35.         echo "<TR><td align=center bgcolor=#EFEFEF><font color=#000000 size=2 face=tahoma><b>" . $pieces[2];           
  36.         echo "</b></td></tr>";
  37.         echo "<td bgcolor=#c0c0c0 align=center><font size=2 color=#003366 face=tahoma>Posted by <B>";
  38.         echo "<a href=$archive?author=$fullname>" . $pieces[1] . "</a>";
  39.         echo "</b> on " . $pieces[0];
  40.         echo " in the <b><a href=$archive?showcat=$pieces[3]>" . $pieces[3] . "</a></b> categoryn";
  41.         echo "</TD></TR>"; }
  42. $newslimit++;
  43. } 
  44. session_unregister("newslimit");
  45. ?>
  46. </table>
  47. </html>

Reply With Quote
  #2  
Old August 2nd, 2002, 09:14 PM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: I updated Matt's News Feed, but...

PS. If anyone wants, I will provide the complete code to the rest of the newslog, not just the display page.

Reply With Quote
  #3  
Old August 2nd, 2002, 09:25 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to notepad
RE: I updated Matt's News Feed, but...

maybe, this tutorial will help?

Reply With Quote
  #4  
Old August 2nd, 2002, 10:19 PM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: I updated Matt's News Feed, but...

Hmmm....I saw that tutorial. I just wanted to do something less dynamic. I think the problem is that it really begs for a foreach loop AND a while loop. It's a small single script that has some options and if statements, and this works...I was just hoping that I could avoid using a session.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > I updated Matt's News Feed, but...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek