Hvordan kan jeg lave en forum søg, som kan vise hvilke tråde bruger har skrevet et indlæg eller tråd i?
min tråd sql (forum_thread) har:
forumid = nummeret for forumet.
author = brugerens id.
subject = emnet.
date = dato (timestamp).
(plus nogle ekstra som jeg ikke tror er nødvendige)
min indlæg sql (forum_post) har:
id = id'et for indlæget.
threadid = nummeret på tråden den hører til.
author = brugerens id.
date = dato (timestamp).
jeg har prøvet sådan, men så kommer den samme tråd flere gange og jeg er nød til at lave to lister i stedet for en:
$getsearch = mysql_query("select id, forumid, subject, message, date, lastediteddate, lastediteduser, editedtotal from forum_thread where author='".$userid."' order by date desc");
if(mysql_num_rows($getsearch) > 0)
{
?>
<table style="padding: 5px;font-size: 12px;" cellspacing="0" cellpadding="0" width="95%" border="0">
<tr><td colspan="3" style="border-bottom:1px solid #ff7f00;"><b>Threads:</b></td></tr>
<tr align="center">
<td style="border-bottom:1px dashed #ff7f00;" width="50%"><b>Thread subject:</b></td>
<td style="border-bottom:1px dashed #ff7f00;" width="30%"><b>Forum title</b></td>
<td style="border-bottom:1px dashed #ff7f00;" width="20%"><b>Date</b></td>
</tr>
<?
while($r = mysql_fetch_array($getsearch))
{
$id = $r[id];
$subject = $r[subject];
$forumid = $r[forumid];
$date = date('d-m-Y H:i',$r[date]);
//Get forum title
$getforum = mysql_query("select title from forum_forum where id='".$forumid."'");
$forumtitle = mysql_fetch_array($getforum);
$forumtitle = $forumtitle[title];
//
echo "<tr align=\\"center\\">";
echo " <td style=\\"border-bottom:1px dashed #ff7f00;\\" width=\\"50%\\"><a href=\\"forum_thread.php?id=$id\\">$subject</a></td>";
echo " <td style=\\"border-bottom:1px dashed #ff7f00;\\" width=\\"30%\\">$forumtitle</td>";
echo " <td style=\\"border-bottom:1px dashed #ff7f00;\\" width=\\"20%\\">$date</td>";
echo "</tr>";
}
?>
</table><br>
<?
}
$getsearch = mysql_query("select id, threadid, date from forum_post where author='".$userid."' order by date desc");
if(mysql_num_rows($getsearch) > 0)
{
?>
<table style="padding: 5px;font-size: 12px;" cellspacing="0" cellpadding="0" width="95%" border="0">
<tr><td colspan="3" style="border-bottom:1px solid #ff7f00;"><b>Posts:</b></td></tr>
<tr align="center">
<td style="border-bottom:1px dashed #ff7f00;" width="50%"><b>Thread subject:</b></td>
<td style="border-bottom:1px dashed #ff7f00;" width="30%"><b>Forum title</b></td>
<td style="border-bottom:1px dashed #ff7f00;" width="20%"><b>Date</b></td>
</tr>
<?
while($r = mysql_fetch_array($getsearch))
{
$id = $r[id];
$threadid = $r[threadid];
//Get subject and forumid
$get = mysql_query("select subject, forumid from forum_thread where id='".$threadid."'");
$t = mysql_fetch_array($get);
$subject = $t[subject];
$forumid = $t[forumid];
//
//Get forum title
$getforum = mysql_query("select title from forum_forum where id='".$forumid."'");
$forumtitle = mysql_fetch_array($getforum);
$forumtitle = $forumtitle[title];
//
$date = date('d-m-Y H:i',$r[date]);
echo "<tr align=\\"center\\">";
echo " <td style=\\"border-bottom:1px dashed #ff7f00;\\" width=\\"50%\\"><a href=\\"forum_thread.php?id=$threadid#$id\\">$subject</a></td>";
echo " <td style=\\"border-bottom:1px dashed #ff7f00;\\" width=\\"30%\\">$forumtitle</td>";
echo " <td style=\\"border-bottom:1px dashed #ff7f00;\\" width=\\"20%\\">$date</td>";
echo "</tr>";
}
?>
</table>
<?
}