Jump to content

Help needed to make this less complicated


almightyegg

Recommended Posts

On my message board there are 4 vital fields for each topic

id - the id of message

fid - which forum it is in

rid - what message it is a reply to (0 if it is top level post)

pid - it's parent thread/top level thread it has been posted under (0 if top level post)

 

When viewing a message under neath are links listing messages posted in reply. EG:

 

Reply 5 - Username

  Reply 7 - Username

Reply 6 - Username

Reply 1 - Username

  Reply 3 - Username

  Reply 4 - Username

  Reply 2 - Username

 

I'm currently using this code to while out the first 5 messages in reply then after that it will show '...more...'

 

<?
while($r2 = mysql_fetch_array($result2)){
$one = mysql_query("SELECT * FROM users WHERE username = '{$r2['username']}'");
$two = mysql_fetch_array($one);
echo "<br><a href=\"/forum/viewthread.php?f=$f&t=$r2[id]\">$r2[title]</a></b> | <a href=\"http://www.lordoftheabyss.com/player/view.php?id=$two[id]\">$r2[username]</a><br>";

$rep1 = mysql_query("SELECT * FROM topics WHERE rid = '{$r2['id']}' and fid = '$f' and deleted = 'No'");
$rep = mysql_num_rows($rep1);
if($rep >= 1){
while($reply = mysql_fetch_array($rep1)){
$one = mysql_query("SELECT * FROM users WHERE username = '{$reply['username']}'");
$two = mysql_fetch_array($one);
echo "          
<b><a href=\"/forum/viewthread.php?f=$f&t=$reply[id]\">$reply[title]</a></b> | <a href=\"http://www.lordoftheabyss.com/player/view.php?id=$two[id]\">$reply[username]</a><br>";

$rep1 = mysql_query("SELECT * FROM topics WHERE rid = '{$reply['id']}' and fid = '$f' and deleted = 'No'");
$rep = mysql_num_rows($rep1);
if($rep >= 1){
while($reply = mysql_fetch_array($rep1)){
$one = mysql_query("SELECT * FROM users WHERE username = '{$reply['username']}'");
$two = mysql_fetch_array($one);
echo "                    
<b><a href=\"/forum/viewthread.php?f=$f&t=$reply[id]\">$reply[title]</a></b> | <a href=\"http://www.lordoftheabyss.com/player/view.php?id=$two[id]\">$reply[username]</a><br>";

$rep1 = mysql_query("SELECT * FROM topics WHERE rid = '{$reply['id']}' and fid = '$f' and deleted = 'No'");
$rep = mysql_num_rows($rep1);
if($rep >= 1){
while($reply = mysql_fetch_array($rep1)){
$one = mysql_query("SELECT * FROM users WHERE username = '{$reply['username']}'");
$two = mysql_fetch_array($one);
echo "                              
<b><a href=\"/forum/viewthread.php?f=$f&t=$reply[id]\">$reply[title]</a></b> | <a href=\"http://www.lordoftheabyss.com/player/view.php?id=$two[id]\">$reply[username]</a><br>";

$rep1 = mysql_query("SELECT * FROM topics WHERE rid = '{$reply['id']}' and fid = '$f' and deleted = 'No'");
$rep = mysql_num_rows($rep1);
if($rep >= 1){
while($reply = mysql_fetch_array($rep1)){
$one = mysql_query("SELECT * FROM users WHERE username = '{$reply['username']}'");
$two = mysql_fetch_array($one);
echo "                                        
<b><a href=\"/forum/viewthread.php?f=$f&t=$reply[id]\">$reply[title]</a></b> | <a href=\"http://www.lordoftheabyss.com/player/view.php?id=$two[id]\">$reply[username]</a><br>";

$rep1 = mysql_query("SELECT * FROM topics WHERE rid = '{$reply['id']}' and fid = '$f' and deleted = 'No'");
$rep = mysql_num_rows($rep1);
if($rep >= 1){
while($reply = mysql_fetch_array($rep1)){
$one = mysql_query("SELECT * FROM users WHERE username = '{$reply['username']}'");
$two = mysql_fetch_array($one);
echo "                                                  
...more...<br>";
}
}
}
}
}
}
}
}
}
}
}
?>

 

problem is, instead of it showing properly, using the above example it will show:

 

Reply 5 - Username

  Reply 7 - Username

Reply 6 - Username

Reply 1 - Username

  Reply 2 - Username

 

as you can see Replies 3 and 4 have gone. Once below the first replies it will only show the oldest message (oldest being the ones with the smallest id) and no others.

 

so 1) What's wrong with my code?

2) Is there any way I could make this easier to do (shorter code, easier to read/adapt)??? perhaps a functon

 

anything put forwardwould be greatly appreciated :)

Link to comment
Share on other sites

oh and another thing I forgot to mention....

How would I make it so it orders by new posts eg:

Reply 2 - Username

    Reply 3 - Username

        Reply 8 - Username

    Reply 5 - Username

Reply 1 - Username

    Reply 4 - Username

        Reply 6 - Username

              Reply 7 - Username

 

Notice Reply 2 appears above Reply 1 because the reply at the bottom of its chain is newer than the one at the bottom of reply 1's chain.

Also Reply 3 appears above Reply 5 for the same reason. How do I make it order like this the whole way down???

Link to comment
Share on other sites

sorry to have to post again but it won't let me modify my posts :-/

 

I think I worked out a way to solve my second post here, or at least the method.

 

I need a function that grabs all the post IDs above a new post.

 

EG:

Reply 1 - Username

    Reply 2 - Username

          Reply 3 - Username

              Reply 5 - Username

                    Reply 7 - Username

                        NEW Reply - Username

                    Reply 6 - Username

Reply 4 - Username

 

For this example, upon inserting the row for the NEW Reply, I would select the IDs of Replies 1, 2, 3, 5 and 7 as that is the chain that leads to it.

 

When I grab these IDs I would update their rows.

Column updatetimestamp would be updated to the newest post's timestamp. This way, when whiling/using a function to echo out the replies to a topic, I can order them by updatetimestamp

 

I think that makes sense anyways. If you need me to explain again I can try

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.