Okay, I am creating a simple forum for my Grade 12 Summative Project, and am having a hard time searching the forum. I have two tables which i would like to search, setup like so:
table1
---------
post_id - AI primary
poster_username
post_subject
post_text
post_time - stored as time() would spit out
table2
---------
reply_id
reply_postid
reply_username
reply_time
reply_text
So, searching the posts subject/text works, I simply do this:
$result = mysql_query("SELECT * FROM posts WHERE post_subject LIKE '%$search%' OR post_text LIKE '%$search%'");
Then Display it like so:
date_default_timezone_set('America/Montreal');
while($r=mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];
//modify these to match your mysql table columns
$date = $r['post_time'];
$date = date("F j, Y, g:i a", $date);
if ($r['post_reported'] != '0')
echo "<tr><td height=40><img src=images/reported.png />{$r['poster_username']}</td><td width=400px><a href=postview.php?post={$r['post_id']}>{$r['post_subject']}</a></td><td>".$date."</td></tr>";
else
echo "<tr><td height=40>{$r['poster_username']}</td><td width=400px><a href=postview.php?post={$r['post_id']}>{$r['post_subject']}</a></td><td>".$date."</td></tr>";
}
However, I want to search the reply table (table2) for reply_text containing the search keyword. Then not display the reply, but display the actual post corresponding to the reply_postid. So I did a search like so:
$result2 = mysql_query("SELECT reply_postid FROM reply WHERE reply_text LIKE '%$search%'");
But then I'm not sure how to combine result 1 and 2 together so that result will also gather the posts which correspond to reply_postid. Also, I don't want the same post shown several times, so I don't know how to remove duplicates in the $result2 variable.
Thanks guys!