Attempted Forum

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
redshrimp2021
Forum Newbie
Posts: 1
Joined: Tue Jul 15, 2008 6:33 am

Attempted Forum

Post by redshrimp2021 »

Hello,
I am trying to create a small type of a forum for user interaction on a web site I am working on for a local church.

When posting a new topic, the four variables are stored in index.js and the total amount of topics is stored in index.log

the only contents of index.log is the total number of topics

index.js

Code: Select all

 
var date1='date'
var title1='title'
var name1='name'
var prayer1='prayer'
 
Index.js is updates by post.php

post.php

Code: Select all

 
 
<?php
 
//retrieves the total topics from index.log as $result
 
$result++;
 
$writeTopic = fopen ( "index.js", "a" );
fwrite ( $writeTopic, "var date".$result."='".date ( "m/d/Y" )."'" );
fwrite ( $writeTopic, "\nvar name".$result."='".$_POST["name"]."'" );
fwrite ( $writeTopic, "\nvar title".$result."='".$_POST["title"]."'" );
fwrite ( $writeTopic, "\nvar prayer".$result."='".$_POST["prayer"]."'\n\n" );
fclose ( $writeTopic );
 
//rewrites $result in index.log
 
?>
 
 
this all works correctly, the problem is displaying the first 30 posts on the home page

home.php?page=1
irrelevant code is missing

Code: Select all

 
<script src="index.js">
</script>
 
<?php
 
//code that retrieves the number from index.log to $result
 
$call = $result;
$pageTest = 30 * $_GET["page"];
$nextPage = 0;
 
if ( $_GET['page'] != 1 )
{
  $st = $_GET['page'] - 1;
    $st = 30 * $st;
    $st = $call - $st;
    $call = $st;
}
else
{
  $num = $call;
}
 
if ( $pageTest < $call )
{
  $nextPage = 1;
    $num = 30;
}
else
{
  $num = $st;
}
 
 
while ( $num > 0 )
{
  echo "<tr bgcolor='#DFE6EF'><td><script language='JavaScript' type='text/javascript'>document.write(date".$call.");</script></td>";
  echo "<td><a href='topic.php?view=".$call."&page=".$_GET['page']."' class='link'><script language='JavaScript' type='text/javascript'>document.write(title".$call.");</script></a></td>";
  echo "<td><script language='JavaScript' type='text/javascript'>document.write(name".$call.");</script></td></tr>";
    $num--;
    $call--;
}
 
echo "</table><br><br>";
 
$dPage = $_GET['page'] + 1;
 
if ( $nextPage == 1 )
{
  echo "<a href='home.php?page=".$dPage."' class='link'>next page</a>";
}
else
{
  echo "next page";
}
 
 ?>
 
 
what's strange is I had 32 topics, and 30 displayed on page=1
and next page turned into a link. When I clicked the link page=2 was displayed and the last two topics were displayed.
Then I posted another topic, when I did so, none of the topics will display. I've restarted and still they won't display.

Any help or ideas would be greatly appreciated.

Thanks,
Travis
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Attempted Forum

Post by Benjamin »

I don't think storing records in a javascript file is the best approach to this problem.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Attempted Forum

Post by omniuni »

Goodness! I agree with Astions!!!

I would recommend you look into http://us.php.net/fputcsv !

fputcsv is a very easy way to store data into a comma separated value file. It will be a bit intensive to parse, but it should still yield much better results.

Other options would be to create an array and file_put_contents(serialize()) it and store it to a file, or try the clever little ffdb project. I've used it for a calendar, it's actually easier than you'd think.

Good luck, though.

-Omni
Post Reply