TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-27-2007, 11:42 PM   #1 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default 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;
        } 
Haris is offline  
Reply With Quote
Old 09-27-2007, 11:52 PM   #2 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

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
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Old 09-28-2007, 05:23 AM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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'];

Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 05:56 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design