How do I retrieve my array from mysql_fetch_array when returned froma class?

[php]function fetchquery()
{
$sql=“SELECT * FROM user”;
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
return $row;
}[/php]
here i m creating the function[php]<?php
require(‘class.php’);
$ob= new abc();
$ob->connection(‘localhost’,‘root’,’’,‘test’);
$row=$ob->fetchquery();
foreach($row as $ro => $re)
//{
//echo"

";
//print_r($row);
//}
//die();
?>
<?php foreach($row as $fo => $re) { ?> <?php } ?>
NAME PHONE EMAIL UPDATE DELETE
<?php echo $row['name'];?> <?php echo $row['phone'] ;?> <?php echo $row['email'] ;?> '>Edit '>Delete
[/php] Thanks for any help this code shows only first row's data form Database 5 times. I need to show entire record content. Plz Help!!!!!!

Hi ankushkalia274,

Your code actualy already explains your mistake.
[php]
$row=mysql_fetch_assoc($result);[/php]
A mysql_fetch_assoc() will only return one row and not the full result.

what I recommend is the following code:

[php]
function fetchquery()
{
$sql=“SELECT * FROM user”;
$result=mysql_query($sql);
return $result;
}

$result = $abc->fetchquery();
while($row = mysql_fetch_assoc($result)) {
//do your stuff
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service