SieRobin Posted March 19, 2006 Share Posted March 19, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/5300-query-trouble/ Share on other sites More sharing options...
hitman6003 Posted March 19, 2006 Share Posted March 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5300-query-trouble/#findComment-18866 Share on other sites More sharing options...
SieRobin Posted March 19, 2006 Author Share Posted March 19, 2006 Alright thanks hitman, I'll try that out and let you know if it works. Quote Link to comment https://forums.phpfreaks.com/topic/5300-query-trouble/#findComment-18911 Share on other sites More sharing options...
SieRobin Posted March 19, 2006 Author Share Posted March 19, 2006 Nope, this is what I get.Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sierobin/public_html/forum.php on line 101 Quote Link to comment https://forums.phpfreaks.com/topic/5300-query-trouble/#findComment-18914 Share on other sites More sharing options...
hitman6003 Posted March 20, 2006 Share Posted March 20, 2006 in your code, change your mysql_query line to something like:[code]$result = mysql_query($query) or die(mysql_error());[/code]The important part being or die(mysql_error()); so that it will show you what is wrong with your query. Quote Link to comment https://forums.phpfreaks.com/topic/5300-query-trouble/#findComment-18917 Share on other sites More sharing options...
SieRobin Posted March 20, 2006 Author Share Posted March 20, 2006 Column 'timep' in order clause is ambiguousThat'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. Quote Link to comment https://forums.phpfreaks.com/topic/5300-query-trouble/#findComment-18919 Share on other sites More sharing options...
hitman6003 Posted March 20, 2006 Share Posted March 20, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/5300-query-trouble/#findComment-18924 Share on other sites More sharing options...
SieRobin Posted March 20, 2006 Author Share Posted March 20, 2006 Yeah I fixed that actually, but now it's just posting the titles for the started thread, and not the reply title. Quote Link to comment https://forums.phpfreaks.com/topic/5300-query-trouble/#findComment-18927 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.