login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Nieuwssystemen > [easy] Nieuws-system, makkelijk te gebruiken

[easy] Nieuws-system, makkelijk te gebruiken

Auteur: ThAlmighty - 09 januari 2006 - 22:20 - Gekeurd door: Maarten - Hits: 18624 - Aantal punten: 3.19 (8 stemmen)



Korte uitleg
De file config.php is voor je database instellingen. Die kan je naar behoren aanpassen. Ook is er een add_news.php, die zou ik eigenlijk zo laten als die is. De news.php kan je weer gewoon vol op eddite.

Zoals je misschien al ziet, doet dit script gegevens enzo in een databaseb stoppen, maar niet het nieuws zelf. Die gaat naar een file waar de url genoteerd staat in de database


Installatie
MySQL query is:

CREATE TABLE `news` (
`id` INT NOT NULL ,
`title` VARCHAR( 100 ) NOT NULL ,
`writer` VARCHAR( 100 ) NOT NULL ,
`posted_at` TEXT NOT NULL ,
`text_url` VARCHAR( 50 ) NOT NULL
) TYPE = MYISAM

De eventuele map die je in de config file instelt, moet je wel zelf aanmaken. Dat stukje moet ik nog erin zetten.

Tot slot
Graag reacties enzo, dit is m'n eerste die ik post en ik wil graag wat tips horen enzo. Kritiek is ook welkom.

Thomas Van der Ploeg


Code:
config.php
  1. <?php
  2. // This is the configration file, below you can set the settings.
  3. // There is also some help, so if you are a noob, you still can
  4. // use this script. Some are filled in by defaults.
  5.  
  6. // Your mysql settings, I think you should know this
  7. $host = 'localhost';
  8. $user = 'root';
  9. $pass = '';
  10. $db = 'news_sys';
  11.  
  12. // Now the url you want to store your txt file's in
  13. $file_url = 'news/';
  14. $file_ext = '.txt';
  15.  
  16. // This was it
  17. // If you don't want to edit the scripts, you can use it for now on
  18. //
  19. // Thomas Van der Ploeg
  20. ?>


add_news.php
  1. <?php
  2. include('config.php');
  3.  
  4. mysql_connect($host, $user, $pass);
  5.  
  6. if($_POST['submit'] && $_POST['title'] && $_POST['writer'] && $_POST['text']){
  7. $sql = "SELECT * FROM news";
  8. $result = mysql_query($sql);
  9. $num = mysql_num_rows($result);
  10.  
  11. if($num == 0){
  12. $id = 0;
  13. }else{
  14. $id = $num;
  15. }
  16.  
  17. $title = $_POST['title'];
  18. $writer = $_POST['writer'];
  19. $text = $_POST['text'];
  20. echo $text."<br>";
  21. $date = date("d-m-Y H:i");
  22.  
  23. $fn = $id.$file_ext;
  24. $fp = fopen($file_url.$fn, 'a');
  25. fputs($fp, $text);
  26. fclose($fp);
  27.  
  28. $sql = "INSERT INTO news (id, title, writer, posted_at, text_url) VALUES ('".$id."', '".$title."', '".$writer."', '".$date."', '".$file_url.$fn."')";
  29. mysql_query($sql);
  30.  
  31. echo '<meta http-equiv="Refresh" content="0;url=add_news.php">';
  32. }else{
  33. ?>
  34. <form method="post" action="<?php echo $PHP_SELF ?>">
  35. <table width="700" border="0" cellspacing="0" cellpadding="0">
  36. <tr>
  37. <td valign="top" width="100">Title</td>
  38. <td><input type="text" name="title"></td>
  39. </tr>
  40. <tr>
  41. <td valign="top" width="100">Writer</td>
  42. <td><input type="text" name="writer"></td>
  43. </tr>
  44. <tr>
  45. <td valign="top" width="100">Your news</td>
  46. <td><textarea cols="75" rows="15" name="text"></textarea></td>
  47. </tr>
  48. <tr>
  49. <td colspan="2"><input name="submit" type="submit" value="Add news"></td>
  50. </tr>
  51. </table>
  52. </form>
  53. <?php
  54. }
  55. ?>


news.php
  1. <?php
  2. // This page can you edit like u want. Important is to keep te config file
  3. // included. You can edit the while loop. That's the most important thing
  4. // for the face of the script
  5.  
  6. include('config.php');
  7.  
  8. mysql_connect($host, $user, $pass);
  9.  
  10. $sql = "SELECT * FROM news";
  11. $result = mysql_query($sql);
  12. $num = mysql_num_rows($result);
  13.  
  14. while($row = mysql_fetch_array($result)){
  15. echo "<font size=4><b>".$row['title']."</b></font><br><font size=1>".$row['writer']."</font>";
  16. echo "<font size=-2> - ".$row['posted_at']."</font><br><br>";
  17. echo "<font size=-1>";
  18. include($row['text_url']);
  19. echo "</font>";
  20. }
  21.  
  22. // All rights reserved
  23. // Thomas Van der Ploeg
  24. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (14)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.04s