Jump to content

How do I store the results of a 'WHILE' loop in a variable


jaisol99

Recommended Posts

I new to php so I may be doing this the wrong way.

 

I'm querying a data base, getting the results out, and I want to insert them into an existing web page.

 

All my php code is in one file.

 

So far I've considered:

1 .Echo-ing all the lines of html code for the page and inserting my loop into that. It seems a bit of an over kill to me but easy.

 

2. Using an include(), but I would have to figure out a way of triggering / calling the correct part of the code

 

3. Inserting the code and functions into the page. Easy but means repeating code thats used elsewhere.

 

4. Get all the results of my WHILE loop into a variable and the just ECHO the variable on the web page. Can this be done and if so how ??

 

Many thanks

james

 

 

 

 

Thank you :)

 

So easy and obvious when I saw it .... and I 've spent all day thinking about it LOL

 

I'll probably just use a single variable rather than an array

eg

 

$info = "echo";

while ($row..

{

$info .= "table layout" . $row[first bit] . "table layout";

$info .= "table layout" . $row[next bit] . "table layout";

..

..

}

$info .= ";"

 

or something along those lines

 

Many thanks again

james

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.