PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 3rd, 2003, 02:52 PM
wannabe wannabe is offline
=) wannabe?
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2002
Location: florida
Posts: 2,153 wannabe User rank is Lance Corporal (50 - 100 Reputation Level)wannabe User rank is Lance Corporal (50 - 100 Reputation Level)wannabe User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 21 h 58 m 25 sec
Reputation Power: 12
Send a message via AIM to wannabe Send a message via Yahoo to wannabe
function problem

this just prints Array ( ). i dont know why.

PHP Code:
function build_pages($table,$array)

{



    $
$array = Array();



    
$getcats mysql_query("SELECT ID,name FROM $table");



    
$mi 0;

    while (
$cat mysql_fetch_array($getcats))

    {

        $
$array["$mi"][0] = $cat['ID'];

        $
$array["$mi"][1] = $cat['name'];

    

        
$mi++;

    }

    return $
$array;



}





$ar build_pages('cats','cats');

print_r($ar); 


i'm not really looking for an alternative. just wondering what it's not working.

thank you

Reply With Quote
  #2  
Old November 3rd, 2003, 03:02 PM
cranium's Avatar
cranium cranium is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: close to the edge
Posts: 1,029 cranium User rank is Second Lieutenant (5000 - 10000 Reputation Level)cranium User rank is Second Lieutenant (5000 - 10000 Reputation Level)cranium User rank is Second Lieutenant (5000 - 10000 Reputation Level)cranium User rank is Second Lieutenant (5000 - 10000 Reputation Level)cranium User rank is Second Lieutenant (5000 - 10000 Reputation Level)cranium User rank is Second Lieutenant (5000 - 10000 Reputation Level)cranium User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 2 h 54 m 7 sec
Reputation Power: 66
Hi,

You are using a variable variable ($$array), therefore when you return $$array, you are only returning the reference of the stuff that it is pointing to, which an array.

You would need to make it $array and do some array manipulation to get the correct output.

I hope that helps,
cranium

Reply With Quote
  #3  
Old November 3rd, 2003, 03:08 PM
Kaleina Kaleina is offline
The Linux-Girl
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 396 Kaleina User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
Re: function problem

Quote:
Originally posted by wannabe
this just prints Array ( ). i dont know why.

i'm not really looking for an alternative. just wondering what it's not working.

thank you


I'm not sure what you need the $array for in your function.. Remove that and the assignment when calling the function Also remove the $$ for array... what's that for? $array=array() will work..

I ran the script on a similar table on my database

print_r($ar) returns the following...

Array ( [0] => Array ( [0] => 1 [1] => Superior Room ) [1] => Array ( [0] => 2 [1] => Deluxe Room ) [2] => Array ( [0] => 3 [1] => Superior City View Studio w/Kitchenette ) [3] => Array ( [0] => 4 [1] => Superior Partial Ocean View Studio w/Kitchenette )

etc...

PHP Code:
function build_pages($table
{
    
$array = Array(); 
    
$getcats mysql_query("SELECT id,name FROM $table") or die(mysql_error());
    
$mi 0//assign 0 to $mi
    
while ($cat mysql_fetch_array($getcats))
    {          
        
$array["$mi"][0] = $cat['id']; //$array[0][0]=$cat['id'];
        
$array["$mi"][1] = $cat['name'];//$array[0][1]=$cat['name']
        
$mi++; //increment $mi         
    
}   
    return 
$array;                       
}   
$ar build_pages('roomcat');
print_r($ar); 
__________________
I am an addiction...
Linux-Girl.Com ... or would you rather look at penguins?
web templates
Debian > RedHat*

Reply With Quote
  #4  
Old November 3rd, 2003, 03:36 PM
wannabe wannabe is offline
=) wannabe?
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2002
Location: florida
Posts: 2,153 wannabe User rank is Lance Corporal (50 - 100 Reputation Level)wannabe User rank is Lance Corporal (50 - 100 Reputation Level)wannabe User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 21 h 58 m 25 sec
Reputation Power: 12
Send a message via AIM to wannabe Send a message via Yahoo to wannabe
ye but why didnt it work.

shouldnt it return an array called $cats. if i pass cats as second argument.

i know it doesnt matter. i'm just wondering why it did it.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > function problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap