Hello PHP developers,
I'm trying to build a website that will contain articles, photos, videos as the page content. More or less I did some scripting and it's working for now. But I don't know if it's an efficient way. Because I'm going to retreive lots of notes from our Facebook page and so there will be huge data to deal with.
For example to display a content, I have article.php, and at the top of this script, I'm looking for a GET variable to be passed. If it's not passed, then I display the list of articles with the title, the first 500 characters of the content and some links at the end such as read more, comment about it, share etc. And for now, I display whatever I have on the table. I don't do pagination. On the other hand, if the variable "id" is passed to the article.php script, then I get only the article having this article id on the table. So I have two functions, and this functions get the data accordingly.
What do you think? Is there anything I should do to improve it? Or can you suggest another way of doing this?
Cheers,
Gungor
<?php
//article.php
include_once 'inc/init.php';
$id = isset($_GET['id']) ? $_GET['id'] : NULL;
include('elem/header.php');
?>
<div id="icerik">
<?php if($id): ?>
<?php $makale = makale_goster($id); ?>
<h2 class="makale"><?php echo $makale['title']; ?></h2>
<div class="zaman"><?php
echo $makale['date'];
if ($user_id == $makale['user_id']) {
echo " - <a href='yonet/makale-duzenle.php?id=".$makale['article_id']."'>Düzenle</a>";
echo " - <a href='yonet/sil.php?makale=".$makale['article_id']."'>Sil</a>";
}
?></div>
<p><?php echo $makale['content']; ?></p>
<div id="baglantilar">
<?php
echo "<a href='#'>Beğen</a>";
echo " - <a href='#yorumlar'>Yorum yap</a>";
echo " - <a href='#'>Paylaş</a>";
if ($user_id == $makale['user_id']) {
echo " - <a href='yonet/makale-duzenle.php?id=".$makale['article_id']."'>Düzenle</a>";
echo " - <a href='yonet/sil.php?makale=".$makale['article_id']."'>Sil</a>";
}
?>
</div>
<a name="yorumlar"></a>
<div id="yorumlar"></div>
<?php else: ?>
<h2>Evrim Ağacı Makale Arşivi</h2>
<a href="yonet/makale-duzenle.php">Makale yaz</a>
<?php makale_listele(); ?>
<?php endif ?>
</div>
<?php include('elem/footer.php');?>
//function to get the article
function makale_goster($article_id) {
$user_id = $_SESSION['user_id'];
$article_id = (int)$article_id;
$result = mysql_query("SELECT * FROM articles WHERE article_id='$article_id'");
$row = mysql_fetch_array($result);
$date = ($row['date_updated'] == "0000-00-00 00:00:00") ? $row['date_created'] : $row['date_updated'];
$date = strtotime($date);
$date = date("j F Y, l, H:i:s", $date);
$row['date'] = tarih($date);
return $row;
}
//function to list articles
function makale_listele() {
$user_id = $_SESSION['user_id'];
$result = mysql_query("SELECT * FROM articles");
while($row = mysql_fetch_array($result))
{
$date = ($row['date_updated'] == "0000-00-00 00:00:00") ? $row['date_created'] : $row['date_updated'];
$date = strtotime($date);
$date = date("j F Y, l, H:i:s", $date);
$date = tarih($date);
echo "<div class='makale_ozet_tablo'>";
echo "<h4><a href='makale.php?id=".$row['article_id']."'>".$row['title']."</a></h4>";
echo "<div class='zaman'>".$date."</div>";
echo "<div class='ozet'>".substr($row['content'], 0, 600)."...</div>";
echo "<a href='makale.php?id=".$row['article_id']."'>Makalenin tamamını gör</a>";
echo " - <a href='#'>Beğen</a>";
echo " - <a href='makale.php?id=".$row['article_id']."#yorumlar'>Yorum yap</a>";
echo " - <a href='#'>Paylaş</a>";
if ($user_id == $row['user_id']) {
echo " - <a href='yonet/makale-duzenle.php?id=".$row['article_id']."'>Düzenle</a>";
echo " - <a href='yonet/sil.php?makale=".$row['article_id']."'>Sil</a>";
}
echo "<div class='clear'></div></div>";
}
}