displaying comments
Moderator: General Moderators
-
misfitxnet
- Forum Newbie
- Posts: 14
- Joined: Mon May 11, 2009 8:40 am
displaying comments
Does anyone know a good way to display comments, posted using a form into a text file, one by one in table rows?
I have figured out how to display all the comments at once, but how would I seperate each comment
into it's own table cell as each comment is posted?
I have figured out how to display all the comments at once, but how would I seperate each comment
into it's own table cell as each comment is posted?
-
ldougherty
- Forum Contributor
- Posts: 103
- Joined: Sun May 03, 2009 11:39 am
Re: displaying comments
Use the file() function
http://us3.php.net/manual/en/function.file.php
file; will reads entire file line by line into an array
Once you have the array generated you can loop through the array using a for each statement, then create a table with each table row as a new line from the array.
Hope that helps.
http://us3.php.net/manual/en/function.file.php
file; will reads entire file line by line into an array
Once you have the array generated you can loop through the array using a for each statement, then create a table with each table row as a new line from the array.
Hope that helps.
-
misfitxnet
- Forum Newbie
- Posts: 14
- Joined: Mon May 11, 2009 8:40 am
Re: displaying comments
Is there anyway to create new table rows for each new line?
-
ldougherty
- Forum Contributor
- Posts: 103
- Joined: Sun May 03, 2009 11:39 am
Re: displaying comments
very simple example which will create 10 new lines reading through an array.
http://us2.php.net/manual/en/control-st ... oreach.php
Code: Select all
<?php
echo "<table border=1>";
$arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
foreach ($arr as &$value) {
echo "<tr><td>$value</td></tr>";
}
echo "</table>";
Last edited by Benjamin on Tue May 12, 2009 7:44 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Reason: Changed code type from text to php.
-
misfitxnet
- Forum Newbie
- Posts: 14
- Joined: Mon May 11, 2009 8:40 am
Re: displaying comments
where can I learn about "For each" statements?
-
misfitxnet
- Forum Newbie
- Posts: 14
- Joined: Mon May 11, 2009 8:40 am
Re: displaying comments
Is it possible to do this with a list() = split() array?
ldougherty wrote:very simple example which will create 10 new lines reading through an array.
http://us2.php.net/manual/en/control-st ... oreach.phpCode: Select all
<?php echo "<table border=1>"; $arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); foreach ($arr as &$value) { echo "<tr><td>$value</td></tr>"; } echo "</table>";
-
misfitxnet
- Forum Newbie
- Posts: 14
- Joined: Mon May 11, 2009 8:40 am
Re: displaying comments
If i have a string, brought to an array of two values, $a and $b,
how would I be able to use "foreach" to incorporate the two
values into tables?
Is for each only able to handle one array, or is it able to reference a list() array,
and then use the variables created within the list() function?
how would I be able to use "foreach" to incorporate the two
values into tables?
Is for each only able to handle one array, or is it able to reference a list() array,
and then use the variables created within the list() function?
-
misfitxnet
- Forum Newbie
- Posts: 14
- Joined: Mon May 11, 2009 8:40 am
Re: displaying comments
Being more specific,
how would I be able to
create a table with two rows,
one variable of an array in each row,
and continue to echo these rows as long as there are variables?
how would I be able to
create a table with two rows,
one variable of an array in each row,
and continue to echo these rows as long as there are variables?
-
ldougherty
- Forum Contributor
- Posts: 103
- Joined: Sun May 03, 2009 11:39 am
Re: displaying comments
What are the two arrays? The output of the text file would be in one array.
Theoretically you can accomplish anything you need to do you just have to think about how logically it should work and then write the code.
Theoretically you can accomplish anything you need to do you just have to think about how logically it should work and then write the code.