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, 08: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, 08: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, 08: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, 09: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!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




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