We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Pages of files
Topic Started: Jun 13 2005, 06:14 PM (571 Views)
JCink
Member
[ *  *  *  *  * ]
Hi I am stuck on something.

I have this code:

Code:
 
<?php
$countstuff = opendir("./forumposts_{$forum}/");
$total_topics = 0;
while($file = readdir($countstuff)){
  if($file != '.' && $file != '..' && $file != 'sticky' ){
     $total_topics++;
  }
}
closedir($countstuff);

if ($total_topics != 0 ) {


$s = "./forumposts_{$forum}/";

 $handle = opendir($s);

 while ( $topic = readdir($handle ))

  {

    if( $topic == '.' || $topic == '..' || $topic == 'sticky' )
   
    continue;
     
    $forumtopiclist [$topic] = filemtime($s."/".$topic);

    }

// use arsort to show them by last modified date
// arsort also lets us have "bumped" topics because it doesnt go by creation but last modified.
// so when a topic is replied to, it gets bumped to the top because then it's "modified"
// get it?

 arsort($forumtopiclist);


 while(list($t)=each($forumtopiclist))

 {


// strip the .txt off the end of the topics.

$thetopic = "$t";

$topicstrip = strrpos($thetopic, '.');

$topictitle = substr($thetopic, 0, $topicstrip);

$counter = "./forumposts_{$forum}/$t";  
$hits = count(file($counter));  

if ($hits < 15) {
$img = "2";
} else {
$img = "0";
}

// ============================
// Pull up who the author is
//============================
$op = 0;
$filename ="./authors_latest/{$forum}_{$topictitle}_author.txt";    
$myFile = fopen($filename, "r");
$fcontents = file($filename);
$grab = $op; {
$yeah = $fcontents[$grab];
if($line != "3"){
echo "";
}
}      
fclose($myFile);


// ============================
// And now the last replier
//============================
$op2 = 0;
$filename2 ="./authors_latest/{$forum}_{$topictitle}_lastreply.txt";    
$myFile2 = fopen($filename2, "r");
$fcontents2 = file($filename2);
$grab2 = $op2; {
$yeah2 = $fcontents2[$grab2];
if($line != "3"){
echo "";
}
}      
fclose($myFile2);



    echo "<tr><td class=arcade1 valign=top></td><td class=arcade1 valign=top><a href='viewtopic.php?topicid=$topictitle&forum=$forum&topicname=$topictitle'>$topictitle</a></td><td class=arcade1 valign=top><div align=center>$hits</div></td><td class=arcade1 valign=top><div align=center>$yeah</div></td><td class=arcade1 valign=top><div align=center>$yeah2</div></td></div>";
  }
} else {

echo "<tr><td class=arcade1 valign=top></td><td class=arcade1 valign=top></td><td class=arcade1 valign=top></td><td class=arcade1 valign=top></td><td class=arcade1 valign=top></td></div>";

}
?>


basically all it really does is show the topics on this page here:
http://jcinkcom.ho8.com/php/sources/admin/...Testing%20Board and it does this by just showing all of the files in a folder, ( this folder to be exact ) and arsorting them.

What I was wondering is... is there a way, with the way I have things setup, to make a code to limit the number of files appearing per page? to about only showing 15 files per page? I honestly have no idea how I would do this...

Thanks in advance...
Offline Profile Quote Post Goto Top
 
solinent
Member
[ *  *  * ]
Well I am not that great at php, but one thing you have done with the .txt thing

Just do

$title = split(".txt", $whateverfilenamelol);
$title = $title[0];

And for your real question....Can't you use a For loop instead of a while loop. You have alot of other things going on there, so I dunno wdh is happening :S

like

if ($_GET['page'] == 1) {
for (i=0;i<15;i++) {
//code for displaying topics on first page...
}
}
else if($_GET['page'] == 2) {
for (i=0;i<15;i++) {
//code for displaying topics on second page...
}
}

and just add like 50 pages lol.. There must be a more efficent way to do it though. I like how you made your own forums...I must try that someday :S
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
You appear to have some errors in your php as well, does this parse? becasue by the looks of it your echos switch from text variables without using ". or ."
Offline Profile Quote Post Goto Top
 
JCink
Member
[ *  *  *  *  * ]
@solinent: thanks, that idea worked somewhat well. I couldn't make pages exactly though with that way, but I made a replacement. Now it just shows 15 topics, and theres a menu below the forums to show last 20, last 50, last 100, etc at least now though it is limited to something.

As far as the other split(); thing, I had no idea it was that easy - someone else had taught me to do it the other way. Thanks.

@kingy: yes that parses.
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
ok...i will remember that for my code, makes things neater
Offline Profile Quote Post Goto Top
 
JCink
Member
[ *  *  *  *  * ]
I have always done: echo "this is a $var"; in my codes and it works every time. Not sure if this is the right thing to do though...
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Of course. Double-quote interpolation of variables is acceptable and useful. If you don't wish variables to be parsed, you use single quotes.
Offline Profile Quote Post Goto Top
 
solinent
Member
[ *  *  * ]
I'm so happy I helped someone :)

And I never knew that single quotes would work like that :S

Seth, that helped me more than you think :lol:

:w00t:
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply