Jump to content

Output loop results outside while...


netphreak

Recommended Posts

Hi to all, my first post here :)

 

I am struggeling hard with what millions of php/html beginners must have had difficulties understanding. I've been reading php.net up and down, and searched google for *many* hours the last couple of days. If I knew exactly what to search for...

 

Here's the situation:

 

I have a while loop gathering information from a MySQL table. The output should be outputed in 3 CSS tables. It's almost impossible to get the php output at the right places! It would be so much easier to have the result from the loop available later down my script (after the endwhile;)... Is that possible? As I understand it, php erases all information from memory once it's finished with executing the loop. Meaning I'd have to store it in my script in some way. I've read so much negative about eval(), but will this function be to any help?

 

Any hints on what to read up on is highly valued :)

 

Link to comment
https://forums.phpfreaks.com/topic/37759-output-loop-results-outside-while/
Share on other sites

I think you're making things more difficult than they need to be. When I output stuff from a mysql table, I just use regular old  HTML tables to do the output, like so,

 

echo "<table><tr><td>Col1</td><td>Col2</td><td>Col3</td></tr>"; //Open the table and display the column titles.
$query = mysql_query(" SELECT * FROM whatever WHERE cheese = pie ");
while($row = mysql_fetch_assoc($query)){
     echo "<tr><td>".$row['col1']."</td><td>".$row['Col2']."</td><td>".$row['Col3']."</td></tr>"; // Output each row each time the loop is looped
}
echo "</table>"; // Close the table

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.