Page 1 of 1

Attempted Forum

Posted: Tue Jul 15, 2008 6:56 am
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

Re: Attempted Forum

Posted: Tue Jul 15, 2008 8:37 pm
by Benjamin
I don't think storing records in a javascript file is the best approach to this problem.

Re: Attempted Forum

Posted: Tue Jul 15, 2008 11:23 pm
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