Welcome to WebmasterWorld Guest from 23.20.241.155

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Inserting data into an array during while

     
11:30 pm on May 26, 2007 (gmt 0)

5+ Year Member



Hello, I'm grabbing content out of a database table, and I'm trying to input it into an array.

Right now, my code will output five records onto the screen. What I would like instead would be to output this content into one array.

How might I do that?

Thanks

$query=mysql_query("SELECT content FROM database LIMIT 5");
while($row=mysql_fetch_array($query)) echo $row["content"];

1:06 am on May 27, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



while($row=mysql_fetch_array($query)) {
$data[] = $row['content'];
echo $row["content"];
}
3:41 am on May 27, 2007 (gmt 0)

5+ Year Member



Thanks for the reply!

I also found that the following script works too!

$array=array();
$query=mysql_query("SELECT content FROM database LIMIT 5");
while($row=mysql_fetch_array($query)) array_push($array,$row["content"]);

4:39 am on May 28, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Just a random tip for the day...

I have observed that using this syntax:


$array[] = $row['content'];

is about twice as fast (on average) than using this:


array_push($array,$row["content"]);

when dealing with large arrays. :)

 

Featured Threads

Hot Threads This Week

Hot Threads This Month