TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   fetch function (http://www.talkphp.com/general/1245-fetch-function.html)

Haris 09-27-2007 11:42 PM

fetch function
 
I have a fetch function in my database class which only echo's out one value (I reckon the last added value but that's not what I want to do. I want to fetch all the values in the array not only the last added value.

How can I achieve this with functions? :confused:

PHP Code:

        /*
         * Summary:     Fetches the result from the datbase in an array
         * Parameters:  SQL Statement
         * Return:      Returns an array of strings that corresponds to the fetched rows
         */
        
        
public function fetch($szSQL){
            
$szResult mysql_query($szSQL);
            
$aResult mysql_fetch_array($szResultMYSQL_ASSOC);
            return 
$aResult;
        } 


CMellor 09-27-2007 11:52 PM

Hmmm... I could be wrong here, but if I'm reading correctly, perhaps try something like so:

Code:

$var = fetch($query);
$var['whatever'];

To get values from an array, try a foreach loop

Tanax 09-28-2007 05:23 AM

PHP Code:

public function fetch($szSQL){
            
$szResult mysql_query($szSQL);
            
$aResult mysql_fetch_array($szResult);
            return 
$aResult;
        } 

PHP Code:

$db = new database();
$sql sprintf("SELECT * FROM `news` WHERE `title` = %s"mysql_escape_string($input));
$results $db->fetch($sql);

foreach(
$results as $news) {
echo 
$news['title'];




All times are GMT. The time now is 07:49 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0