Jump to content

Query Trouble


SieRobin

Recommended Posts

I have a forum on my website, and when you go to forum.php there is "Last Posts" that I've created to show who last posted what. Now what it displays is the Title of the reply and the Author. The problem I'm having is that in the MySQL Database there are two different tables, f_thread and f_post.

In f_threads it displays all the newly started threads f_post is just the replies to the threads, and they're ordered by a number containing. How can I make it display both newly started threads and replies on the Last Posts thing, so that when someone posts a new thread it also displays as a last post.

Perhaps there is a way to use one query to pull the tables both? I'm not sure, but hmmn, if someone could help I'd appreciate it.

[code]    $last="SELECT * FROM  f_post order by timep DESC limit 5";
    $last2=mysql_query($last) or die("Could not retrieve posts");
    print "</table>
    <br><table class='table'><tr class='headline'><td align='center' colspan='2'>Last Posts</td></tr>
    <tr><td class='mainrowb'>Title</td><td class='mainrowb'>Author</td></tr>";
    while ($last3=mysql_fetch_array($last2)) {
    print "<tr class='mainrow'><td><a href='forum.php?brd=$last3[bname]&msg=$last3[msg]'>$last3[title]</a></td><td><a href='profile.php?id=$last3[UID]'>$last3[author]</a></td></tr>";
      }[/code]
Link to comment
Share on other sites

You'll probably have to adjust your column names...but I think this will work:

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]f_post,[/color] f_thread [color=green]ORDER BY[/color] timep [color=green]DESC[/color] LIMIT 5 [!--sql2--][/div][!--sql3--]

Instead of the SELECT *, select only the fields that you need from your tables...I don't know your column names from f_thread, but from f_post it looks like you would only need bname, msg, title, UID, author...so change the * to "f_post.bname, f_post.msg, f_post.title, f_post.UID, f_post.author" followed by the fields needed from the f_thread table, using the same "tablename.fieldname" format.
Link to comment
Share on other sites

Column 'timep' in order clause is ambiguous

That's what it says lol.

I think I might have gotten it figured out, but just one thing.

The only thing it's doing weird, is that it's using the same title as in the thread title. So the replies never log actual titles, hmmn.
Link to comment
Share on other sites

[!--quoteo(post=356531:date=Mar 19 2006, 07:23 PM:name=Christopher Robin)--][div class=\'quotetop\']QUOTE(Christopher Robin @ Mar 19 2006, 07:23 PM) [snapback]356531[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Column 'timep' in order clause is ambiguous
[/quote]

That means that that column exists in more than one table. Specify which table you want it to select from in your query by doing tablename.timep.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.