Page 1 of 1

return Array from mysql

Posted: Tue Nov 02, 2010 6:05 pm
by roeyhaim
Hello.
I'm new to php and need a little help please.
I try to build a class that return an Array of all the table in my db.
and be able to get all the data by there col name (like username, password....)
but all i got is the last record from the db.
here is the class:

Code: Select all

<?php
    class db{
            function getall($table, $search){           
            $sql = "SELECT ". $search ." FROM " . $table;
            $result = mysql_query($sql) or die('Error, insert query failed' . mysql_error());
            while($row=mysql_fetch_assoc($result)){
                     $data = $row;
             }
            return $data;
}
and this is in the html page:

Code: Select all

$data = $db->getall("users", "*");
    foreach($data as $row){
        echo $row['fullname'];
        echo "<BR>";
}

can anybody help me with that?

Re: return Array from mysql

Posted: Tue Nov 02, 2010 10:57 pm
by yacahuma

Code: Select all

    function getTablesMysql()
        {
            $sql = "show tables";
            $rs = $this->db->Execute($sql);
            $arr = array();
            if ($rs)
            {
                while (!$rs->EOF)
                {
                    $arr[] = $rs->fields[0];
                    $rs->MoveNext();
                }
            }
            return $arr;

        }
PS: this is using ADODB