Forum Moderators: coopster

Message Too Old, No Replies

getting data from while loop into string

         

foy

1:33 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



I'd like to get data from a mysql_query into one single string, i.e.

$data = mysql_query("SELECT * FROM table");
while ($row = mysql_fetch_object($data)) {
$row->data1.$row->.data2.$row->data3 ...
}

So how do I get all the data that is being fetched within the while loop into one string outside of the loop?

if I put $data = $row->data1... it gives me an error.

thx for any help.

carneddau

2:18 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



If you just want all of the data "dumped" into a variable try:

$data .= $row->data1 . $row->data2;

inside the loop.

Then after the loop:

echo $data;

Netizen

2:30 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



You shouldn't use $data inside the loop as it contains mysql_query handle id. Try something like:

$data = mysql_query("SELECT * FROM table");

while ($row = mysql_fetch_object($data)) {
$string.=$row->data1.$row->data2.$row->data3."\n";
}

echo $string;

etc...

carneddau

11:23 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



Doh! that's what happens when you don't read the post properly before pressing submit.