Page 1 of 1

[SOLVED] data from mysql_fetch_array

Posted: Mon Nov 24, 2003 2:35 am
by patejl
hey all,
for data collecting and printing from mysql i'm using mysql_fetch_array statement. e.g.

while ($area=mysql_fetch_array($result)){
print $area["name"];
}

$area is acitve only in while loop. how to store whole arrary for later use? when while {} is over $area not exist.

hope you understand me ;)
p.

Posted: Mon Nov 24, 2003 2:48 am
by twigletmac
You need to save the data to another array:

Code: Select all

while ($row = mysql_fetch_assoc($result)) {
    $area['name'][] = $row['name'];
}

// then later you can do something like
echo '<ul>';
foreach ($area['name'] as $name) {
    echo '<li>'.$name.'</li>';
}
echo '</ul>';
Mac

Posted: Mon Nov 24, 2003 3:01 am
by infolock

Code: Select all

<?php
echo '<ul>'; 
foreach ($area['name'] as $name) { 
    echo '<li>'.$name.'</li>'; 
} 
echo '</ul>';
?>

or you could also do this :

Code: Select all

<?php
$name = array();
while ($row = mysql_fetch_assoc($result))
{
     $name[] = $row['name'];
}

// and call it like this 

for($i=0; $i<=count($name); $i++)
{
    echo $name[$i];
}

?>

Posted: Mon Nov 24, 2003 4:54 am
by patejl
great. so easy :)
thx a lot...

p.