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
<?php
Class news
{
public $mysqli;
public $mysql="**";
public $user="**";
public $password="**";
public $datebase="**";
function __construct(){
$this->mysqli = new mysqli($this->mysql,$this->user,$this->password,$this->datebase);
$this->mysqli->query("SET NAMES utf8");
if ($mysqli->connect_error){
die('Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); }
}
function __deconstruct(){
unset($mysql,$datebase,$password,$user); }
public function ShowAll($howmuch){
$query=$this->mysqli->query("SELECT * from `news` ORDER BY id DESC LIMIT 0,$howmuch");
while($results=$query->fetch_assoc())
{
<h1><a href=\"\">$results[temat]</a></h1>
".substr($results['tresc'],0,300)."... <div class=\"comments\"> <a href=\"index.php?page=read_more&id=".intval($results[id
])."\">read more</a> | Autor: $results[autor] | $results[date]</div> </div>";
}
}
public function readmore(){
$query=$this->mysqli->query("SELECT * from `news` WHERE `id`=$_GET[id]");
while($results=$query->fetch_assoc())
{
<h1><a href=\"\">$results[temat]</a></h1>
$results[tresc]
<div class=\"comments\"><a href=\"index.php\">Back main page</a> | Autor: $results[autor] | $results[date]</div>
</div>";
}
}
}
?>
Index.php
<?php
include_once("class.php");
$news=new news();
?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<title>Komentarz v1.0.0</title>
</head>
<body>
<div id="content">
<h4>System newsów oparty o MySql</h4>
<?php
switch($_GET['page'])
{
case "read_more":
$news->readmore();
break;
default:
$news->ShowAll(3);
}
?>
</div>
</body>
</html>
Mysql
-- phpMyAdmin SQL Dump
-- version 3.2.4
-- <a href="http://www.phpmyadmin.net" target="_blank">http://www.phpmyadmin.net</a>
--
-- Host: localhost
-- Czas wygenerowania: 19 Kwi 2010, 19:13
-- Wersja serwera: 5.1.41
-- Wersja PHP: 5.3.1
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Baza danych: `news`
--
-- --------------------------------------------------------
--
-- Struktura tabeli dla `news`
--
CREATE TABLE IF NOT EXISTS `news` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Id news',
`autor` varchar(24) NOT NULL COMMENT 'autor',
`temat` varchar(35) NOT NULL COMMENT 'temat newsa',
`tresc` text NOT NULL COMMENT 'tresc',
`date` date NOT NULL COMMENT 'data dodania',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=13;
--
-- Zrzut danych tabeli `news`
--
INSERT INTO `news` (`id`, `autor`, `temat`, `tresc`, `date`) VALUES
(12, 'Podgur', 'Siema jestem eniu', 'Eniu nowy kolega nasz.siala', '2010-04-19'),
(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'),
(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');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Bless!
Ten post edytował podgur 19.04.2010, 18:30:03