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
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 07-14-2009, 07:42 PM   #1 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default Returning an array from a function

I want to create a function that goes away and collects data from a database that will be used in a form drop down. I assume the best way to do this is an array as the number of rows of data returned will vary. Essentially i want to build an array as i read th rows then return the array from the function. How do I go about doing this and how do I handle the data when calling the function. the code I have inside the function (PS i havent included all the function code just the main part of it):

PHP Code:
    function getList($data1,$data2) {

        
$query = ("SELECT blahdata from blahtable
        WHERE blahcolumn == "
$data1");
          
        
$result = mysql_query($query) OR die("Cannot perform getList query!");

        if (mysql_num_rows(
$result) == 0) {
            return 0;
        } else {
            
$arr=array();
            
$counter=0;
            while(
$row = mysql_fetch_array($result))
            {
                
$arr[$counter]=$row['blahdata'];
                
$counter=$counter+1;
            }
            return 
$arr;            
        }
            
    } 
I find if I call the function using a print statement I get "0" when there is no rows as expected but "array" when there ares rows. Do i need to explode the array?
captainmerton is offline  
Reply With Quote
 



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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
feedback on my class please frostyboy33 Advanced PHP Programming 7 10-22-2012 09:12 AM
How to delete array element in function benton General 4 04-02-2009 01:12 AM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
Part 1: Getting Started with Array Functions Wildhoney Absolute Beginners 6 10-01-2007 10:53 AM


All times are GMT. The time now is 07:25 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