•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,970 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,773 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1472 | Replies: 6
![]() |
•
•
Join Date: Jul 2007
Posts: 111
Reputation:
Rep Power: 2
Solved Threads: 2
Hi im having some trouble with the code bellow. I would like for each time the form containing the name and message to be echoed out but in a table. So naturally i have made a for loop that checks the amount in the array and echo out seperate portions of the data in a table.
Please .. any help would be so apreciative
<?
//host form values in variables
$name = $HTTP_POST_VARS["name"];
$message = $HTTP_POST_VARS["message"];
$write = $name."|".$message."|";
//open the blog.txt
$fp = fopen("blogfile.txt","a+") or die("Counld not open file");
//writing to the file and closing
fwrite($fp, $write);
fclose($fp);
//split the variable $write at | making an array
$finished = explode('|',$write);
//count the entries in the blog
$amount = count($finished);
?>
<table bgcolor="#47607C" border="2" cellpadding="5" bordercolor="#003333" style="color:#003366;" width="500px">
<tr>
<td width=40><font color="#000000">Name</font></td>
<td width=200><font color="#000000">Message</font></td>
</tr>
<?php
for($i=0; $i<$amount ; $i = $i+2)
{
if(empty($finished[$i]) || $finished[$i] == null)
continue;
echo "<tr>";
echo "<td>".$finished[$i]."</td><td>".$finished[$i+1]."</td>";
echo "</tr>";
}
?>
</table>
The code in Bold is where i think the problem is.
Thanks
Please .. any help would be so apreciative
<?
//host form values in variables
$name = $HTTP_POST_VARS["name"];
$message = $HTTP_POST_VARS["message"];
$write = $name."|".$message."|";
//open the blog.txt
$fp = fopen("blogfile.txt","a+") or die("Counld not open file");
//writing to the file and closing
fwrite($fp, $write);
fclose($fp);
//split the variable $write at | making an array
$finished = explode('|',$write);
//count the entries in the blog
$amount = count($finished);
?>
<table bgcolor="#47607C" border="2" cellpadding="5" bordercolor="#003333" style="color:#003366;" width="500px">
<tr>
<td width=40><font color="#000000">Name</font></td>
<td width=200><font color="#000000">Message</font></td>
</tr>
<?php
for($i=0; $i<$amount ; $i = $i+2)
{
if(empty($finished[$i]) || $finished[$i] == null)
continue;
echo "<tr>";
echo "<td>".$finished[$i]."</td><td>".$finished[$i+1]."</td>";
echo "</tr>";
}
?>
</table>
The code in Bold is where i think the problem is.
Thanks
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 636
Reputation:
Rep Power: 3
Solved Threads: 71
•
•
Join Date: Jul 2007
Posts: 111
Reputation:
Rep Power: 2
Solved Threads: 2
yes thats it, it does not repeat the table for the amount of data entries. Which makes me think that the following is the problem . But i cant see what.
for($i=0; $i<$amount ; $i = $i+2)
{
if(empty($finished[$i]) || $finished[$i] == null)
continue;
echo "<tr>";
echo "<td>".$finished[$i]."</td><td>".$finished[$i+1]."</td>";
echo "</tr>";
}
for($i=0; $i<$amount ; $i = $i+2)
{
if(empty($finished[$i]) || $finished[$i] == null)
continue;
echo "<tr>";
echo "<td>".$finished[$i]."</td><td>".$finished[$i+1]."</td>";
echo "</tr>";
}
•
•
Join Date: Jul 2007
Posts: 111
Reputation:
Rep Power: 2
Solved Threads: 2
i have just uploaded it to my server
http://www.reecesplace.co.uk/Reecesplace/blog/blog.php
if u fill it in once on the next page it echoes into the table but if you try it again it just echoes the new data and doesnt repeat what i wanted in the for loop. Please help
http://www.reecesplace.co.uk/Reecesplace/blog/blog.php
if u fill it in once on the next page it echoes into the table but if you try it again it just echoes the new data and doesnt repeat what i wanted in the for loop. Please help
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 636
Reputation:
Rep Power: 3
Solved Threads: 71
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 636
Reputation:
Rep Power: 3
Solved Threads: 71
here, i wrote this:
it works perfectly for me. make sure you delete everything in your blogfile.txt file first though. it won't work other wise. if you have any questions, just let me know and i will answer them
<?php
$name = $_REQUEST['name'];
$message = $_REQUEST['message'];
$file = 'blogfile.txt';
$error = 0;
if ($name == '') {
$error++;
}
if ($message == '') {
$error++;
}
if ($error > 0) {
echo 'No fields can be left blank';
}
if ($error == 0) {
$open = fopen($file, 'a');
$data = "--" . $name . "|" . $message . "\n";
$write = fwrite($open, $data);
fclose($open);
}
$open = fopen($file, 'r');
$read = fread($open, filesize($file));
fclose($open);
$entries = explode('--', $read);
$delete = array_shift($entries);
echo '<table bgcolor="#47607C" border="2" cellpadding="5" bordercolor="#003333" style="color:#003366;" width="500px">';
echo '<tr>';
echo '<td width=40><font color="#000000">Name</font></td>';
echo '<td width=200><font color="#000000">Message</font></td>';
echo '</tr>';
$i = 0;
while ($i < count($entries)) {
$info = explode('|', $entries[$i]);
echo '<tr>';
echo '<td>' . $info[0] . '</td><td>' . $info[1] . '</td>';
echo '</tr>';
$i++;
}
echo '</table>';
?>it works perfectly for me. make sure you delete everything in your blogfile.txt file first though. it won't work other wise. if you have any questions, just let me know and i will answer them
Last edited by kkeith29 : Nov 25th, 2007 at 4:49 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Virus scanner file(php) cannot be executed (PHP)
- The Definitive Guide to which Forum Software Information (Growing an Online Community)
- HELP! I get an erro when including PEAR.php file (PHP)
- PHP - subscribers' email (PHP)
- Huge flat file (Visual Basic 4 / 5 / 6)
- php download a file without redirecting (PHP)
- new to php, need help adding a forum (PHP)
- help executing a .wav file with php code (PHP)
- Error when editing PHP lines in a theme file. (PHP)
Other Threads in the PHP Forum
- Previous Thread: replace string
- Next Thread: hyperlink in php


Linear Mode