我想从 mysql 获取新闻(记录)并使用 PHP 在我的站点中显示。这是我的代码(PHP):
<?php
include ("header.php");
mysql_connect ("localhost", "root", "") or die (mysql_error());
mysql_select_db ("geek-art") or die (mysql_error());
$newsy = mysql_query ("SELECT * FROM newsy order by id desc");
// With this WHILE loop, I want to display all of my news :)
while ($rekord = mysql_fetch_array ($newsy)) {
$id = $rekord['id'];
$tytul = $rekord['tytul'];
$tresc = $rekord['tresc'];
$autor = $rekord['autor'];
$data = $rekord['data'];
$obrazek = $rekord['obr-news'];
echo '<div class="artykul">';
echo "<h2><a href=\"index.php?news=$id\">".$tytul.'</a></h2>';
echo '<span>Autor: '.$autor.' Data: '.$data.'</span>';
echo '<p>'.nl2br($tresc).'</p>';
echo '</div>';
}
// With this WHILE loop, I want to display my news :)
$newsy_osobne = mysql_query("SELECT * FROM newsy where id=".(int)@$_GET['news']."");
while($rekordy_osobne = mysql_fetch_array($newsy_osobne)){
if(isset($_GET['news'])){
$id = $rekordy_osobne['id'];
$tytul = $rekordy_osobne['tytul'];
$tresc = $rekordy_osobne['tresc'];
$autor = $rekordy_osobne['autor'];
$data = $rekordy_osobne['data'];
echo '<div class="artykul">';
echo "<h2>".$tytul.'</a></h2>';
echo '<span>Autor: '.$autor.' Data: '.$data.'</span>';
echo '<p>'.nl2br($tresc).'</p>';
echo '</div>';
}else{
echo 'Nie znaleziono takiego newsa.';
}
}
include ("footer.php");
?>
我做了一个简短的视频,在那里我展示了我的问题到底是什么:)