FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Forum - Help





Diablosblizz
Hey, I got a forum script from a site (nothing like PHPBB), and It's pretty good. The only problem I am having is after the stickys are shown, I want the posts to show up in a list depending on which thread was posted in last.

Example:

Forum Name

STICKY
Test 1
Test 2


I go into Test 2, and post, then afterwards it shows:

Forum Name

STICKY
Test 2
Test 1

I hope you understand...

Code:
$fetch2 = mysql_query("SELECT * FROM `forum_thread` WHERE `top_id` = '$_GET[id]' ORDER BY `sticky` DESC"); // get mysql
echo "<tr></table><table width='100%' cellspacing='0'>"; // end, then start table
while ($thread = mysql_fetch_array($fetch2))
{
$threadtitle = "$thread[title]";
$bbctt1 = BBCODE($threadtitle);
if($thread[locked] == Yes) {   // CHECKS IF LOCKED, IF IT IS DISPLAY
echo "<tr><td width='10%'><center><img src='/images/locked.gif'></center></td>";
} else { // ELSE DISPLAY
echo "<td width='10%'></td>";   
}
if($thread[sticky] == Yes) {    // CHECKS IF ITS STICKYED, IF IT IS DISPLAY
echo "<td width='40%'><img src='/images/stickyforum.gif'> - <a href='?page=forumdisplay&id=$thread[id]'> &nbsp;$bbctt1</a><td>";
} else { // ELSE DISPLAY
echo "<td width='40%'><a href='?page=forumdisplay&id=$thread[id]'>&nbsp;$bbctt1</a><td>";   
}
echo "
<td width='10%'><a href='/members/members.php?username=$thread[poster]'>$thread[poster]</a></td>
<td width='10%'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;?</td>
<td width='30%'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;?</td></tr><tr>";   
} // ABOVE SHOWS THE REST, WHICH DOESN'T NEED TO BE IN THE ELSES


That's the bit where it shows the forum names, and threads.

If nobody can figure this out, then if somebody could tell me how to do this:

Code:
$fetch2 = mysql_query("SELECT * FROM `forum_thread` WHERE `top_id` = '$_GET[id]' ORDER BY `sticky` DESC");


If you look at the code above, it orders by sticky, is it possible to do something like:

Code:
$fetch2 = mysql_query("SELECT * FROM `forum_thread` WHERE `top_id` = '$_GET[id]' ORDER BY `sticky` THEN `something here` DESC");


I was wondering cause it would be easier because it would display the stickys, then afterwards the rest (including the example above)...


So, pretty much, I want it to reorder the forums that ARE NOT STICKED below the stickys...

I hope you understand, this seems to be a big problem for me. Thanks A LOT guys!!
DjinniFire
I'm not sure about that mysql_query you are hoping exists but I think concept wise for it to display from

    Sticky 1
    Sticky 2
    Thread 1
    Thread 2


to

    Sticky 1
    Sticky 2
    Thread 2
    Thread 1


if somebody posts in Thread 2. I would do something like this:

Add a activity column to your database for all threads. When a user post in the thread run a script to UPDATE the activity to the time at the moment the person posts. Now every thread a person posts will be presented with last activity time. Then you can just order the thread database by activity (which is the date and time). I would believe this works, however this is just the concept I would think is how you do.
Diablosblizz
Yes, my thoughts exactly! But, I don't know how to do it after the stickys... Sad
DjinniFire
Make a second query.

The first query searches for all posts that are marked "stickied"
and shows them,
while the second query searches for all posts that are not marked stickied,
and then shows them.
Diablosblizz
Yes, but I have to make it AFTER the stickys.... so far I got it semi working... :@

Now, the table doesn't expand all the way. Bah, this is way to confusing.
Diablosblizz
Code:
$fetch3 = mysql_query("SELECT * FROM `forum_thread` WHERE `top_id` = '$_GET[id]' ORDER BY `act` DESC");
$threads = mysql_fetch_array($fetch3);   
echo "<table width='90%' cellspacing='0'><td width='40%'>&nbsp;<a href='?page=forumdisplay&id=$threads[id]'>$bbctt1</a><td><td width='10%'><a href='/members/members.php?username=$threads[poster]'>$threads[poster]</a></td>
<td width='10%'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;?</td>
<td width='30%'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;?</td></tr></table>


Alright, I got this and it displays them, but doesn't order them.

I have two posts in database, one with 1 as the act, and one as 2. It should go.

STICKY
2
1

But it goes

STICKY
1
2

And I can't change it.... Evil or Very Mad
mathiaus
Does this work? It's better than having two queries.
Code:
$fetch2 = mysql_query("SELECT * FROM `forum_thread` WHERE `top_id` = '$_GET[id]' ORDER BY `sticky`, `act` DESC");




The code you posted above won't do much I don't think. $threads is now an array which you need to loop through, which your not. So it will show a table with one empty row. Did you change the original query? If not, its that which is still showing the normal topics. Try my single query above.
Diablosblizz
Okay, yeah that does work BUT it does this:

Topic 1
Topic 2
STICKY

It will alter depending on the number that is on `act` so far here is what the numbers are (in the same order)

2
1
1

2 being the highest. So... I could make the stickys something like 99999999999... but... is there an easier way? :S
mathiaus
Sorry Embarassed
Code:
$fetch2 = mysql_query("SELECT * FROM `forum_thread` WHERE `top_id` = '$_GET[id]' ORDER BY `sticky` DESC, `act` DESC");


What is the act by the way? Unless it keeps changing the order of all topics it seems rather pointless. Is there a date field or one where each one will be different (higher each time)?
Diablosblizz
The act part will be a date, but for now it's just simply numbers.

Code:
$fetch2 = mysql_query("SELECT * FROM `forum_thread` WHERE `top_id` = '$_GET[id]' ORDER BY `sticky` DESC, `act` DESC");


IT WORKS!!!! Smile THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Smile
Diablosblizz
Okay, now I am having more problems. Well, sort of...

Code:
$getposted = mysql_query("SELECT * FROM `forum_thread`");
$getposted2 = mysql_fetch_array($getposted);

$posts = $getposted2['posts'] + 1;
$user = $logged['username'];
$date = date("jwnYHis");
$thread = mysql_query("UPDATE `forum_thread` SET `posts` = '$posts', `act` = '$date', `last` = '$user' WHERE `id` = '$id'");


My problem:

The first time somebody posts it adds one (if its 0), but now it doesn't add (for the $posts)...


The rest works fine, but the adding one to the $getposted2.

I have tried removing the 's from $getposed2['posts'] and I have added ' and " around 1, and still nothing.

I also put the $posts variable in an echo and it displayed one, when it should have displayed something like two.

So... once again, what did I do wrong?
mathiaus
You have an array of all the threads (You selected everything rather than a specific thread). $getposted2['posts'] doesn't exist as such you actually have $getposted2[0]['posts'] $getposted2[1]['posts'] etc. Selecting the one thread you are referring to should solve this.
Code:
$getposted = mysql_query("SELECT * FROM `forum_thread`WHERE `id` = '$id'");
Diablosblizz
Ah, thank you.
Related topics
php forum help
PROBLEMS ABOUT A PHP FORUM
Best PHP forum
php-nuke - Forum Help (phpbb)
PHP installtion Help!
php script help!
please help! problems with phpbb forum installation.
PHP Layout Help -- URGENT
My Forum
php forum
PhpBB2 forum help
Templates to the php forum help me
PHP Forum???
php project help needed please
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.