Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.