Blog Entries Problem

Hey All,

Yes yet another question to our Kirupa php masters in my php learns. :smiley:

I’ve been working on scriping a simple blog…I’ve got it so it will read data from a txt file and insert it into all the fields I need to group information together to make a small simple blog…the problem is it will just not create a new entry to the blog when I insert it into the txt file :bad: Now the reason it doesn’t work it because I havn’t been able to find the code to make a certain bit of html an entry template or however you would make that work.

Does anyone have an idea as where a tutorial might be on this or even a bit of code?

Thanks again everyone and sorry for not being able to understand this more,

-Data :sketchy:

Code in next post ->

Do I use the explode command to make a new entry explode or will I have to write some new code to tell the script to create a new table header and all when .:::. or whatever is typed?

-Data :sketchy:

not at all… try something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Julian's  Simple Blog</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="main.css" rel="stylesheet" type="text/css">
<link href="stylesheets/main.css" rel="stylesheet" type="text/css">
</head>

<body>
<?php
// Gets contents of a file into a string
$filename = "entries.txt";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
// Explodes data at entry breaks
$entries = explode(".:::.", $contents);  // creates the entries
fclose ($handle);
?>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" valign="middle">
  <tr>
    <td><div align="center">
      </div>
      <table width="75%" height="90%" border="0" align="center" cellpadding="20" cellspacing="0" class="bodyContent">
        <tr>
          <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2" class="entryTitle">
		  <?php 
		  		for($x=0; $x < count($entries); $x++){     // begin for loop for the number of entries
		  			$line = explode("|", $entries[$x]);	   // split the current entry into the different lines...		
		  ?>
              <tr>
                <td width="48%"><?php echo ($line[2]); ?></td>
                <td width="50%" class="entryInfo"><div align="right"&gt<img src="images/smilies/tongue.gif" border="0" alt="">Poster: <?php echo ($line[0]); ?>,
                    Date: <?php echo ($line[1]); ?></div>
                </td>
              </tr>
            </table>
              <p><?php echo ($line[3]); ?></p>
              <p align="center"><img src="images/entry-divider.gif" width="600" height="1"></p>
          </td>
        </tr>
		<?
				}  // ends the for loop
		?>
      </table></td>
  </tr>
</table>
</body>
</html>

the only changes I made are commented. If you need me to explain I will, but this is kind of what I mean… you may have to make some adjustments on the HTML side of things…

Well thanks a bunch Jubba for the code and it does work but it doesn’t create a new table.

http://www.unknowndesigns.net/julian/blog/beta.php

See it has to create a new title table on new entry.

Thanks a load for the code again,
-Data :sketchy:

yeah that just has to do with where I put the for loop… I’ll see if I can weed thru the code and get the proper placement…


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Julian's  Simple Blog</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="main.css" rel="stylesheet" type="text/css">
<link href="stylesheets/main.css" rel="stylesheet" type="text/css">
</head>

<body>
<?php
// Gets contents of a file into a string
$filename = "entries.txt";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
// Explodes data at entry breaks
$entries = explode(".:::.", $contents);  // creates the entries
fclose ($handle);
?>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" valign="middle">
          <?php 
                  for($x=0; $x < count($entries); $x++){     // begin for loop for the number of entries
                      $line = explode("|", $entries[$x]);       // split the current entry into the different lines...        
          ?>


<tr>
    <td><div align="center">
      </div>
      <table width="75%" height="90%" border="0" align="center" cellpadding="20" cellspacing="0" class="bodyContent">
        <tr>
          <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2" class="entryTitle">
                        <tr>
                <td width="48%"><?php echo ($line[2]); ?></td>
                <td width="50%" class="entryInfo"><div align="right"&gt<img src="images/smilies/tongue.gif" border="0" alt=""&gt<img src="images/smilies/tongue.gif" border="0" alt="">oster: <?php echo ($line[0]); ?>,
                    Date: <?php echo ($line[1]); ?></div>
                </td>
              </tr>
            </table>
              <p><?php echo ($line[3]); ?></p>
              <p align="center"><img src="images/entry-divider.gif" width="600" height="1"></p>
          </td>
        </tr>
              </table></td>
  </tr>
        <?
                }  // ends the for loop
        ?>
</table>
</body>
</html>

That should do it… I think… I don’t really know the layout you are going after, but now it should work and from there you should be able to fix it. :slight_smile:

http://www.unknowndesigns.net/julian/blog/beta.php

The only problem now is the spacing between entries. I wanted it all in the same table but with new titles and breaks but hey it WORKS!

Thanks again Jubba for all your help and support. :slight_smile:

-Data :sketchy:

well basically all you need to do is put what you want to be repeated in between the for loop. That is something that you will have to do. I’m sure you can mess with the HTML and figure it out from here.

whats the actual code? how are you trying to implemtent it?