Content from table td - into the variable

Hey there,

I have following code:
[php]…

<?php foreach ($data as $row) : ?>
                <tr>
                    <td><?php echo $row['nickname']; ?></td>
                    <td><?php echo $row['comment']; ?></td>
                    <td><?php echo $row['meaning']; ?></td>
                </tr>
            <?php endforeach; ?>

…[/php]
I need to get text from second td, so $row[‘comment’]; and put in into new variable so I can use it for further analyze.
For example, something like:

[php]$something = $row[‘comment’];[/php]

Note that this is from “foreach” loop, so I need all printed rows from that “td”, not just first one or something like that.

Thanks!

Not understanding. You have that values, as well as the others, already in a variable to use whenever you wish… in the $data array.

What is the actual issue?

Thanks for your quick answer astonecipher.

The thing is, that I need all text from “comment” inside one variable, so I can analyze it and print out the results at the end of that page.

So, the part of the code i posted above is the one that construct 3 rows inside the table. Those tables are printed and after all of that I’d like to use all comments to see frequency of some phrases, words inside etc.
I guess that I should make new variable and add all values from “comment” inside the while loop or something like that, but I’m kinda stuck there.

So, create a variable and append it.

[php]$out .= ‘whatever’;[/php]

If you add that into the foreach loop, it will consecutively add the value to the last, resulting in one enormous string.

Sponsor our Newsletter | Privacy Policy | Terms of Service