nu har man kämpat med detta forumet, men det börjat ta sig.
har några problem som jag inte vet hur jag ska kunna lösa..
Hoppas att någon har någon lösning.
Forum main (kod 1)
- Visa vem som lagt in sista inlägget(username) med datum
Category (kod 2)
- Dölja "skapa ny tråd" om man inte är inloggad
- Visa 0 på första inlägget istället för 1
topic (kod 3)
- Dölja redigera om man inte är inloggad, men ska synas om man e inloggad.
och man ska kunna redigera sina egna och inte dom andras.
- Dölja snabb meddelande om man inte e inloggad.
- Visa text om man låst tråden.
kod1
<?php
$sql = "SELECT
cat_id AS id,
cat_name AS name,
cat_description AS description,
cat_order,
cat_group AS groupname
FROM
categories
ORDER BY
cat_id, cat_order";
$result = mysql_query($sql)or die(mysql_error());
$headline = '';
while($row = mysql_fetch_assoc($result))
{
if ($headline != $row['groupname'])
{
echo '<div class="home-header"><div class="heading ico-groups">' . $row['groupname'] . '
</div></div>';
}
echo '<table border="0" cellspacing="0" cellpadding="3" class="tableCurves" width="100%">
<tr>
<td>';
echo '<table border="0" cellspacing="1" cellpadding="4" width="100%">
<tr>
<td valign="top" align="center" width="3%"><img src="img/topic_icon_on.png" width="22" height="22" alt="" /></td>';
echo '<td valign="top" width="53%"><b><a href="category.php?id=' . $row['id'] . '">' . $row['name'] . '</a></b><br />' . $row['description'] . '</td>';
//fetch last topic for each cat
$topicsql = "SELECT
u.username AS username,
u.id AS userid,
t.topic_id AS topic_id,
t.topic_date AS topic_date,
t.topic_cat AS topic_cat
FROM
(SELECT
topic_by AS userid,
topic_id AS topic_id,
topic_date AS topic_date,
topic_cat AS topic_cat
FROM
topics
WHERE
topic_cat = " . $row['id'] . "
ORDER BY
topic_id, topic_date DESC
LIMIT 1) AS t
JOIN
users AS u
ON
u.id = t.userid";
$topicsresult = mysql_query($topicsql)or die(mysql_error());
if(!$topicsresult)
{
echo 'Last topic could not be displayed.';
}
else
{
if(mysql_num_rows($topicsresult) == 0)
{
echo '<td valign="top" align="center" width="8%"></td>';
echo '<td valign="top" align="center" width="8%">-</td>
<td valign="top" align="center" width="19%">';
echo 'Inga ämnen';
}
else
{
while($topicrow = mysql_fetch_assoc($topicsresult))
{
echo '<td valign="top" align="center" width="8%">'
. mysql_result(mysql_query("SELECT COUNT(*) FROM topics WHERE topic_cat=" . $row['id']), 0, 0)
. '</td>';
echo '<td valign="top" align="center" width="8%">-</td>
<td valign="top" align="center" width="19%">' . $topicrow['username'] . '<br />';
echo '<a href="topic.php?id=' . $topicrow['topic_id'] . '"> ' . date('j F, Y, g:i', strtotime($topicrow['topic_date']));
echo '</a></td>';
echo '</tr>';
}
}
}
echo '<tr>
<td class="trow1" valign="top" align="center" colspan="5"><div style="border-bottom:1px dotted #94B1DF; margin-bottom:5px; padding:0px 0px 5px 0px; clear:both;"></div></td>
</tr>
</table>
</td></tr></table>';
}
?>
kod 2
<?php
$sql = "SELECT
cat_id,
cat_name,
cat_description,
cat_count
FROM
categories
WHERE
cat_id = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
if(!$result)
{
echo 'The category could not be displayed, please try again later.' . mysql_error();
}
else
{
if(mysql_num_rows($result) == 0)
{
echo 'This category does not exist.';
}
else
{
//display category data
while($row = mysql_fetch_assoc($result))
{
echo '<div class="heading ico-groups">' . $row['cat_name'] . '</div>
<div class="quicklinks2"><a href="create_topic.php"><b>Skapa ny tråd</b></a></div>
</div>
<table border="0" cellspacing="0" cellpadding="3" class="tableCurves" width="100%">
<tr>
<td>
<div id="conversations">
<ul class="list conversationList">';
}
//do a query for the topics
$sql = "SELECT
topic_id,
topic_subject,
topic_date,
topic_by,
topic_cat,
users.username,
users.id
FROM
topics
JOIN
users
ON
users.id = topics.topic_by
WHERE
topic_cat = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql) or die(mysql_error());
if(!$result)
{
echo 'The topics could not be displayed, please try again later.';
}
else
{
if(mysql_num_rows($result) == 0)
{
echo '<br>Det finns inga trådar i denna kategori ännu<br>';
}
else
{
while($row = mysql_fetch_assoc($result))
{
$bildfil = "avatar/no.gif";
foreach (glob('avatar/' . $row['topic_by'] . '_*') as $bild)
{
$bildfil = $bild;
}
echo '<li id="c31" class="channel-4">
<div class="col-conversation"><strong class="title"><a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a></strong></div>';
echo '<div class="col-lastPost">';
echo '<span class="action"><img src="' . $bildfil . '" class="avatar thumb" alt="" />';
echo '' . $row['username'] . '';
echo '<span class="lastPostMember name"></span></span></div>';
echo '<div class="col-replies"><span>Antal svar: '
. mysql_result(mysql_query("SELECT COUNT(*) FROM posts WHERE post_topic=" . $row['topic_id']), 0, 0)
. '</span></div></li>';
}
}
}
}
}
?>
kod 3
<?php
include 'bbcode.php';
$sql = "SELECT
topic_id,
topic_subject,
topic_by
FROM
topics
WHERE
topics.topic_id = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
if(!$result)
{
echo 'The topic could not be displayed, please try again later.';
}
else
{
if(mysql_num_rows($result) == 0)
{
echo 'This topic doesn′t exist.';
}
else
{
while($row = mysql_fetch_assoc($result))
{
//display post data
echo '<div class="home-header">
<div class="heading ico-groups" style="width: 850px; height:25px">' . $row['topic_subject'] . '</div>';
if (isset($_SESSION['sess_rank']) && $_SESSION['sess_rank'] != 1)
{
echo '<div class="quicklinks2"><a href="las_trad.php?block=' . $row['topic_id'] . '"><b>Lås</b></a></div>';
}
echo '</div>
<table border="0" cellspacing="0" cellpadding="3" class="tableCurves" width="100%">
<tr>
<td>
<!-- Conversation header -->
<div id="conversationHeader" class="bodyHeader">
<!-- Posts -->
<ol id="conversationPosts" class="postList" start="1">';
//fetch the posts from the database
$posts_sql = "SELECT
posts.post_topic,
posts.post_content,
posts.post_date,
posts.post_by,
posts.post_block,
users.username,
users.id
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.id
WHERE
posts.post_topic = " . mysql_real_escape_string($_GET['id']);
$posts_result = mysql_query($posts_sql) or die(mysql_error());
if(!$posts_result)
{
echo 'The posts could not be displayed, please try again later.';
}
else
{
while($posts_row = mysql_fetch_assoc($posts_result))
{
$bildfil = "avatar/no.gif";
foreach (glob('avatar/' . $row['topic_by'] . '_*') as $bild)
{
$bildfil = $bild;
}
if ($posts_row['post_block'] == 1) {
echo "<table border=\"0\" width=\"100%\">
<tr>
<td width=\"50\"><img src=\"img/forum_read_locked.gif\"></td>
<td>Denna tråd är låst<br>Det går ej att skriva inlägg på denna tråd..</td>
</tr>
</table>";
}
else
{
echo '<li data-index="201111">
<div class="post hasControls " id="p213" data-id="213">
<div class="avatar">
<a href="visa.php?user=' . $posts_row['id'] . '"><img src="' . $bildfil . '" class="avatar" alt="" /></a></div>
<div class="postContent thing">
<div class="postHeader">
<div class="info">
<h3><a href="visa.php?user=' . $posts_row['id'] . '" title="Visa volvo_owners profil">' . $posts_row['username'] . '</a></h3> ' . date('d-m-Y H:i', strtotime($posts_row['post_date'])) . '';
// Om inte inloggad visa formulär, annars logga ut-länk
if (!isset($_SESSION['sess_id']))
{
echo '- <a href="edit.php?id=' . $posts_row['topic_id'] . '">Redigera</a>
<span class="group"></span></div>
<div class="controls"></div></div>
<div class="postBody">';
echo nl2br(BBCode($posts_row['post_content']));
echo '</div>
</div></div></li>';
}
else
{
echo '<span class="group"></span></div>
<div class="controls"></div></div>
<div class="postBody">';
echo nl2br(BBCode($posts_row['post_content']));
echo '</div>
</div></div></li>';
}
}
}
if(!$_SESSION['sess_id'])
{
echo '</ol></td>
</tr>
</table>
<br><div class="home-header">
<div class="heading ico-groups" style="width: 850px; height:25px">Skriv ditt meddelande och klicka på skicka</div>
</div>
<table border="0" cellspacing="0" cellpadding="3" class="tableCurves" width="100%">
<tr>
<td>Du måste vara <a a class="example5" href="login.php">inloggad</a> för att kunna svara.</td>
</tr>
</table>
</div>';
}
else
{
//show reply box
echo '</ol></td>
</tr>
</table>
<br>
<div class="home-header">
<div class="heading ico-groups" style="width: 850px; height:25px">Skriv ditt meddelande och klicka på skicka</div>
</div>
<table border="0" cellspacing="0" cellpadding="3" class="tableCurves" width="100%">
<tr>
<td><form method="post" action="reply.php?id=' . $row['topic_id'] . '">
<textarea name="reply-content" rows="13" cols="100"></textarea></textarea><br />
<a class="example5" href="bbcode.htm">BBCode:</a> på
<br /><br />
<input type="submit" value="Skicka svar" />
</form></div></td>
</tr>
</table>
</div>';
}
}
}
}
}
?>