Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Skrypt newsów do Waszej opinii
podgur
post
Post #1





Grupa: Zarejestrowani
Postów: 21
Pomógł: 1
Dołączył: 6.04.2009

Ostrzeżenie: (0%)
-----


Witam. Napisałem skrypt newsów i proszę Was o opinie( co można pozmieniać, co lepiej zrobić, co zmienić itd.) : )
Wiem że to nie wiele, ale wole wiedzieć jak można poprawić go (IMG:style_emoticons/default/tongue.gif)
Za wszystkie opinie dziękuje:)

Class.php
  1. <?php
  2.  
  3. Class news
  4. {
  5.  
  6. public $mysqli;
  7. public $mysql="**";
  8. public $user="**";
  9. public $password="**";
  10. public $datebase="**";
  11.  
  12.  
  13. function __construct(){
  14.  
  15.  
  16. $this->mysqli = new mysqli($this->mysql,$this->user,$this->password,$this->datebase);
  17. $this->mysqli->query("SET NAMES utf8");
  18. if ($mysqli->connect_error){
  19. die('Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error);
  20. }
  21.  
  22.  
  23. }
  24.  
  25. function __deconstruct(){
  26. unset($mysql,$datebase,$password,$user);
  27. }
  28.  
  29.  
  30. public function ShowAll($howmuch){
  31.  
  32. $query=$this->mysqli->query("SELECT * from `news` ORDER BY id DESC LIMIT 0,$howmuch");
  33. while($results=$query->fetch_assoc())
  34. {
  35. echo"<div class=\"box\">
  36. <h1><a href=\"\">$results[temat]</a></h1>
  37. ".substr($results['tresc'],0,300)."...
  38. <div class=\"comments\"> <a href=\"index.php?page=read_more&id=".intval($results[id])."\">read more</a> | Autor: $results[autor] | $results[date]</div>
  39. </div>";
  40.  
  41. }
  42.  
  43. }
  44.  
  45.  
  46. public function readmore(){
  47.  
  48. $query=$this->mysqli->query("SELECT * from `news` WHERE `id`=$_GET[id]");
  49. while($results=$query->fetch_assoc())
  50. {
  51. echo"<div class=\"box\">
  52. <h1><a href=\"\">$results[temat]</a></h1>
  53. $results[tresc]
  54. <div class=\"comments\"><a href=\"index.php\">Back main page</a> | Autor: $results[autor] | $results[date]</div>
  55. </div>";
  56.  
  57. }
  58.  
  59. }
  60. }
  61.  
  62. ?>


Index.php
  1. <?php
  2. include_once("class.php");
  3. $news=new news();
  4.  
  5. ?>
  6. <!DOCTYPE html
  7. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  8. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
  12. <link rel="stylesheet" type="text/css" href="css/style.css" />
  13. <title>Komentarz v1.0.0</title>
  14. </head>
  15. <body>
  16. <div id="content">
  17. <h4>System newsów oparty o MySql</h4>
  18.  
  19. <?php
  20. switch($_GET['page'])
  21. {
  22. case "read_more":
  23. $news->readmore();
  24. break;
  25. default:
  26. $news->ShowAll(3);
  27. }
  28. ?>
  29.  
  30. </div>
  31. </body>
  32. </html>

Mysql
  1. -- phpMyAdmin SQL Dump
  2. -- version 3.2.4
  3. -- <a href="http://www.phpmyadmin.net" target="_blank">http://www.phpmyadmin.net</a>
  4. --
  5. -- Host: localhost
  6. -- Czas wygenerowania: 19 Kwi 2010, 19:13
  7. -- Wersja serwera: 5.1.41
  8. -- Wersja PHP: 5.3.1
  9.  
  10. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  11.  
  12.  
  13. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  14. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  15. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  16. /*!40101 SET NAMES utf8 */;
  17.  
  18. --
  19. -- Baza danych: `news`
  20. --
  21.  
  22. -- --------------------------------------------------------
  23.  
  24. --
  25. -- Struktura tabeli dla `news`
  26. --
  27.  
  28. CREATE TABLE IF NOT EXISTS `news` (
  29. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Id news',
  30. `autor` varchar(24) NOT NULL COMMENT 'autor',
  31. `temat` varchar(35) NOT NULL COMMENT 'temat newsa',
  32. `tresc` text NOT NULL COMMENT 'tresc',
  33. `date` date NOT NULL COMMENT 'data dodania',
  34. PRIMARY KEY (`id`)
  35. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=13;
  36.  
  37. --
  38. -- Zrzut danych tabeli `news`
  39. --
  40.  
  41. INSERT INTO `news` (`id`, `autor`, `temat`, `tresc`, `date`) VALUES
  42. (12, 'Podgur', 'Siema jestem eniu', 'Eniu nowy kolega nasz.siala', '2010-04-19'),
  43. (11, 'Gues9000', 'Polska 0-6 Węgry', 'W dzisiejszym meczu polska reprezentacja hokeja przegrała 2 mecz na mistrzostwach świata pierwszej diwizji. Wynikiem 6-0 zakończył się mecz polaków.', '0000-00-00'),
  44. (10, 'Podgur', 'Lech Kaczyński żyje!?', 'Nulla elementum odio sit amet nibh commodo pharetra. Proin non luctus leo. Nunc mollis pharetra est aliquet tristique. Integer posuere magna in est placerat tempus. Maecenas adipiscing sodales mattis. Sed nec erat ac leo imperdiet eleifend vel id purus. Praesent nec libero quis dolor elementum vestibulum. Etiam turpis mi, viverra sit amet elementum ut, consequat nec ligula. Suspendisse in velit eu magna sagittis vestibulum. Quisque mattis nulla auctor neque scelerisque ut euismod tortor ultricies.', '2010-04-15');
  45.  
  46. /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  47. /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  48. /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


Bless!

Ten post edytował podgur 19.04.2010, 18:30:03
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 21:08