Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 26th, 2007, 05:10 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default function problem in php

Hi everybody...
i m using php4.2, mysql, apache on linux

I have an php function problem..! Some code of my one php file has used in in two different files, which working proper without any problem.

This code gives filled (calldate) values (dates in formate of dd/mm/yyyy) from database (telephone), and split dd, mm, yyyy as unique only (means non repeaded only) The code is:-


$monthyr= "select calldate from billtable";
        $myresult= execute_query($monthyr);

//execute_query function is defined by me and working well

                $k=0;
                $distmonth = array();
        while($row = mysql_fetch_array($myresult))
                {
                $calldate= $row['calldate'];
                list($days, $months, $year1)=split("/", $calldate);
                $months;
                list($years)=split(" ", $year1);

                $distyear[$k]=$years;
                $distmonth[$k] = $months;
                $k=$k+1;
                }

                $umonth = array_unique($distmonth);
                asort($umonth);
                $valm=array_values($umonth);
                $countm=count($valm);

                $uyear = array_unique($distyear);
                asort($uyear);
                $valy=array_values($uyear);
                $county=count($valy)

I had upload bills in table billtable of two years-2007 and 2006
and 4 months 05, 06, 07 and 08

I had retrieve months (05,06,07 and 07) and year (2006 and 2007)in drop down list, which is working well.....

.....BUT when i put it in a function and call that function then it show only one randamly chosen or earliear select month and year only....

Please tell me anyone why is it not show all 4 months and 2 years in drop down list while it is working when write whole code without function....pleaz help me...

 thanx in advance





 
Old November 26th, 2007, 05:33 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 Hi everybody...
i m using php4.2, mysql, apache on linux

I have an php function problem..! Some code of my one php file has used in in two different files, which working proper without any problem.

This code gives filled (calldate) values (dates in formate of dd/mm/yyyy) from database (telephone), and split dd, mm, yyyy as unique only (means non repeaded only) The code is:-


$monthyr= "select calldate from billtable";
        $myresult= execute_query($monthyr);

//execute_query function is defined by me and working well

                $k=0;
                $distmonth = array();
        while($row = mysql_fetch_array($myresult))
                {
                $calldate= $row['calldate'];
                list($days, $months, $year1)=split("/", $calldate);
                $months;
                list($years)=split(" ", $year1);

                $distyear[$k]=$years;
                $distmonth[$k] = $months;
                $k=$k+1;
                }

                $umonth = array_unique($distmonth);
                asort($umonth);
                $valm=array_values($umonth);
                $countm=count($valm);

                $uyear = array_unique($distyear);
                asort($uyear);
                $valy=array_values($uyear);
                $county=count($valy)

I had upload bills in table billtable of two years-2007 and 2006
and 4 months 05, 06, 07 and 08

I had retrieve months (05,06,07 and 07) and year (2006 and 2007)in drop down list, which is working well.....

.....BUT when i put it in a function and call that function then it show only one randamly chosen or earliear select month and year only....

Please tell me anyone why is it not show all 4 months and 2 years in drop down list while it is working when write whole code in the function in same file. It gives nothing if this function is kept another file/dir/folder while the the exact file has inluded with correct path........
....pleaz help me...

 thanx in advance





 
Old November 27th, 2007, 05:45 PM
Registered User
 
Join Date: Nov 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

rapraj

can you show how do you put it in a function?


---------------
Canon PowerShot SD1000
http://astore.amazon.com/powershot08-20
 
Old November 29th, 2007, 02:43 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default




Quote:
quote:Originally posted by Pektsekye
 rapraj

can you show how do you put it in a function?


---------------
Canon PowerShot SD1000
http://astore.amazon.com/powershot08-20
Thanx vary much for this help........!
Here is the function in witch form i used it..

function findmonthyear()
{
$monthyr= "select distinct calldate from billtable";
        $myresult= execute_query($monthyr);
                $k=0;
                $distmonth = array();
                while($row = mysql_fetch_array($myresult))
                        {
                        $calldate= $row['calldate'];
                        list($days, $months, $year1)=split("/", $calldate);
                        $months;
                        list($years)=split(" ", $year1);

                        $distyear[$k]=$years;
                        $distmonth[$k] = $months;
                        $k=$k+1;
                        }

                $umonth = array_unique($distmonth);
                asort($umonth);
                $valm=array_values($umonth);
                $countm=count($valm);

                $uyear = array_unique($distyear);
                asort($uyear);
                $valy=array_values($uyear);
                $county=count($valy);

     }


I call this method by syntax as-

findmonthyear();

 
Old November 29th, 2007, 03:05 PM
Registered User
 
Join Date: Nov 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but there is no "return" in this function

and i cannot find $distyear initialization
it must be
$distyear = array();

before while(...


---------------
Canon PowerShot SD1000
http://astore.amazon.com/powershot08-20

 
Old December 1st, 2007, 07:18 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well thanks for reply...but problem is that i have required to display one (arrays) values in drop down list of months and another (array) of years.....S..0...So how can return two arrays from one function...?

Can i return more than one arrays (containing to many values like 01,02,03,04... and 2006,2007,2008...etc respectively)?

Thanx for help once again...


Quote:
quote:Originally posted by Pektsekye
 but there is no "return" in this function

and i cannot find $distyear initialization
it must be
$distyear = array();

before while(...


---------------
Canon PowerShot SD1000
http://astore.amazon.com/powershot08-20

 
Old December 9th, 2007, 11:00 AM
Registered User
 
Join Date: Nov 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

of course you can

just create another array and put those two arrays in it
Code:
$ret_arr [months] = $umonth; 
$ret_arr [years] = $uyear;
and then return it:
Code:
return $ret_arr;

---------------
Canon PowerShot SD1000
http://astore.amazon.com/powershot08-20

 
Old December 11th, 2007, 05:38 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Pektsekye
 of course you can

just create another array and put those two arrays in it
Code:
$ret_arr [months] = $umonth; 
$ret_arr [years] = $uyear;
and then return it:
Code:
return $ret_arr;

---------------
Canon PowerShot SD1000
http://astore.amazon.com/powershot08-20


W..ell.. Thanx for this help...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Php Error when calling the cart() control function krifur BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 11 February 23rd, 2013 02:28 AM
XSLT php:function: call objects non static method polarbear Pro PHP 1 June 6th, 2008 05:39 PM
Developing javascript function using PHP and XML abishasharaf ADO.NET 1 September 28th, 2004 01:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.