Ausnahmsweise ..
admin.php - Einfügen neuer News.
PHP:
<?php
$mysql_db="DATENBANK";
$db=mysql_connect("SERVER","USER","PASSWORD");
if($news_save)
{
$result=mysql_db_query($mysql_db,"
SELECT max(id) as max_id
FROM news");
$max_id=(mysql_fetch_array($result));
$counter=(($max_id['max_id']) + 1);
mysql_db_query($mysql_db ,"
INSERT INTO news (`id`, `news`, `autor`, `datum`, `zeit`)
VALUES('$counter','$news','$autor','$datum','$zeit')");
}
$result=mysql_db_query($mysql_db,"
SELECT max(id) FROM news");
$max_id=(mysql_fetch_row($result));
$max_id=(($max_id[0]));
$result=mysql_db_query($mysql_db,"
SELECT *
FROM news
WHERE id='$max_id'");
$result=(mysql_fetch_row($result));
$news=(($result[1]));
$autor=(($result[2]));
echo("
<form action='$PHP_SELF' method='post'>
<input type='text name='autor' maxlength='15' value='$autor'>
<br>
<textarea type='text' name='news' cols='55' rows='10'>$news
</textarea>
<br>
<input type='submit' name='news_save' value='save'>
</form>
\n");
?>
news.php - Die darstellende Datei.
PHP:
<?php
$mysql_db="DATENBANK";
$db=mysql_connect("SERVER","USER","PASSWORD");
if($comment_save)
{
if($c_name=='Name' OR $c_text=='blablub');
else
{
$c_name=htmlentities($c_name);
$c_text=htmlentities($c_text);
mysql_db_query($mysql_db,"
INSERT INTO news_comment
(id,news_id,comment,autor,datum,zeit)
VALUES
('','$news_id','$c_text','$c_name','$datum','$zeit')");
}
}
if(!$news_id)
{
$max_id=mysql_db_query($mysql_db,"
SELECT max(id)
FROM news");
$max_id=mysql_fetch_row($max_id);
$max_id=$max_id[0];
$news_query=mysql_db_query($mysql_db,"
SELECT *
FROM news
ORDER BY id DESC
LIMIT 0, 30");
while($news=mysql_fetch_row($news_query))
{
$news_id=$news[0];
$count=mysql_db_query($mysql_db,"
SELECT comment
FROM news_comment
WHERE news_id='".$news_id."'");
$count=mysql_num_rows($count);
$n_date=explode("-",$news[3]);
$n_datum="$n_date[2]-$n_date[1]-$n_date[0]";
$n_zeit=$news[4];
echo("$n_zeit - $n_datum<br>
$news[1]
<br>
Kommentare :
<a href='$PHP_SELFnews_id=$news_id#comment'>".$count."</a>
<br>");
$i++;
}
}
else
{
$news_query=mysql_db_query($mysql_db,"
SELECT *
FROM news
WHERE id='$news_id';");
while($news=mysql_fetch_row($news_query))
{
echo("$news[2] - $news[3]<br>
$news[1]<br>
<a name='comment'>Comments</a><br>\n");
$query=mysql_db_query($mysql_db,"
SELECT *
FROM news_comment
WHERE news_id='$news_id';");
$count_query=mysql_num_rows($query);
if($count_query=='0')
{
echo("Noch keine Kommentare.\n");
}
else
{
while($comment=mysql_fetch_row($query))
{
$nx_date=explode("-",$comment[4]);
$nx_date="$nx_date[2]-$nx_date[1]-$nx_date[0]";
$nx_time=$comment[5];
echo("$comment[3] [$nx_date : $nx_time]<br>
$comment[2]<br>");
}
}
echo("<form action='$PHP_self?news_id=$news_id' method='post'>
<input type='text' name='c_name' value='Name'>
<textarea name='c_text' cols='15'rows='5'>blablub</textarea>
<input type='hidden' name='news_id' value='$news_id'>
<input type='submit' name='comment_save' value='kommentieren'>
</form>\n");
}
}
?>
Aber nachher kein Gemecker wegen fehlender DB Daten und so ..
Und es gibt (wie üblich) keine Garantien für fehlerfreie Skripte.
Sonst lernt ihr ja garnichts ..
Hier die DBStruktur :
# Tabellenstruktur für Tabelle `news`
CREATE TABLE news (
id int(11) NOT NULL auto_increment,
news varchar(250) NOT NULL default '',
autor varchar(15) NOT NULL default '',
datum date NOT NULL default '0000-00-00',
zeit time NOT NULL default '00:00:00',
PRIMARY KEY (id)
) TYPE=MyISAM;
# Tabellenstruktur für Tabelle `news_comment`
CREATE TABLE news_comment (
id int(11) NOT NULL auto_increment,
news_id int(11) NOT NULL default '0',
comment varchar(250) NOT NULL default '',
autor varchar(15) NOT NULL default '',
datum date NOT NULL default '0000-00-00',
zeit time NOT NULL default '00:00:00',
PRIMARY KEY (id)
) TYPE=MyISAM;
Pfote, Kojote