jaisol99 Posted October 10, 2009 Share Posted October 10, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/177248-how-do-i-store-the-results-of-a-while-loop-in-a-variable/ Share on other sites More sharing options...
.josh Posted October 10, 2009 Share Posted October 10, 2009 while ($row = mysql_fetch...) { $info[] = $row; } // do what you want with $info Quote Link to comment https://forums.phpfreaks.com/topic/177248-how-do-i-store-the-results-of-a-while-loop-in-a-variable/#findComment-934600 Share on other sites More sharing options...
jaisol99 Posted October 11, 2009 Author Share Posted October 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/177248-how-do-i-store-the-results-of-a-while-loop-in-a-variable/#findComment-934626 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.