datadoit
|
| Posted: 02/26/2008, 10:50 AM |
|
CCS3.2; PHP5; MySQL5
Anyone know how to build an array of listbox values of the last 100
years and place them into a CCS listbox?
$Component->Values = array(array("2008","2008"),array("2007","2007"));
How can I build that array in an array? :)
for ($i <= 100; $i++) {
$array .= (date("Y")-$i); ????
}
$Component->Values = array($array);
|
|
|
 |
datadoit
|
| Posted: 03/01/2008, 6:34 PM |
|
Anyone know how to do this? I found this function:
<code>
function list_years($list_name, $num_years, $sel_year = '') {
$list .= "<select name=$list_name>\n";
if ($sel_year == '') $list .= "<option value=''>Year</option>\n";
$year = date("Y"); //get current year
for ($k=0; $k<$num_years; ++$k) {
if ($sel_year == $year)$list .= "<option value=$year
selected>$year</option>\n";
else $list .= "<option value=$year>$year</option>\n";
$year += 1;
}
$list .= "</select>\n";
echo $list;
}
</code>
But I'd like to use CodeCharge's method of dynamically modifying listbox
values.
|
|
|
 |
magus
Posts: 98
|
| Posted: 03/01/2008, 7:14 PM |
|
Greetings,
The array structure to use when dynamically assigning a list of options to a listBox control is.
$values[] = array($db->f($bound_column), $db->f($text_column));
Once you have all your values in the $values array you can put the next code in the component's before show event.
$Component->Values = $values;
function listbox_years($num_years) {
$year = date("Y"); //get current year
for ($k=0; $k<$num_years; ++$k) {
$values[] = array($year,$year);
$year += 1;
}
return $values;
}
In the listbox component before show event
$num_years = 10; // eg
$Component->Values = listbox_years($num_years);
Regards,
Don A
|
 |
 |
magus
Posts: 98
|
| Posted: 03/02/2008, 12:07 AM |
|
After a bit more of a play here is a more flexible function to generate years ranges for a variety of conditions.
function listbox_years($num_years = 5, $offset = 0, $direction = "asc") {
/*
// Usage in listbox, radiolist or checkboxlist components before show.
// usage
$Component->Values = listbox_years(10);
// 15 years back from current year e.g searching library catalogue
$Component->Values = listbox_years(15, 0, 'desc');
// 5 years forward from current year current first e.g credit card
$Component->Values = listbox_years(5, 0, 'asc');
// 5 years forward from current year newest first
$Component->Values = listbox_years(5, 4, 'desc');
// 5 years back, current first
$Component->Values = listbox_years(5, 0, 'desc');
// Last 5 years oldest first.
$Component->Values = listbox_years(5, -4, 'asc');
// 10 year span newest first, current in middle
$Component->Values = listbox_years(10, 5, 'desc');
*/
$increment = ($direction == 'asc') ? 1 : -1 ;
$year = date("Y"); //get current year
$year= $year + $offset;
for ($k=0; $k<$num_years; ++$k) {
$values[] = array($year,$year);
$year += $increment;
}
return $values;
}
|
 |
 |
datadoit
|
| Posted: 03/02/2008, 7:23 AM |
|
Works great DonA! Thanks.
Here's the final I used in the listbox BeforeShow:
//Dynamically build the year values.
$year = date("Y"); //get current year
for ($k=0; $k<100; ++$k) {
$values[] = array($year, $year);
$year -= 1;
}
$Component->Values = $values;
Now off to see how to dynamically build a listbox of the proper number
of days (including this leap year!) based on the value of a month
listbox selection (dependent listboxes).
|
|
|
 |
wkempees
Posts: 1679
|
| Posted: 03/02/2008, 11:28 AM |
|
if the selected year can be divided by 4
and it is not a century than feb=29
Does anybody know which month has 28 days.......
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
DonB
|
| Posted: 03/03/2008, 5:01 AM |
|
Um, all of them?
--
DonB
"wkempees" <wkempees@forum.codecharge> wrote in message
news:547caffe11b285@news.codecharge.com...
> if the selected year can be divided by 4
> and it is not a century than feb=29
>
> Does anybody know which month has 28 days.......
>
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
wkempees
|
| Posted: 03/03/2008, 2:01 PM |
|
lol
"DonB" <~ccbth~@gotodon.com> schreef in bericht
news:fqgsro$3bs$1@news.codecharge.com...
> Um, all of them?
>
> --
> DonB
>
>
>
> "wkempees" <wkempees@forum.codecharge> wrote in message
>news:547caffe11b285@news.codecharge.com...
>> if the selected year can be divided by 4
>> and it is not a century than feb=29
>>
>> Does anybody know which month has 28 days.......
>>
>>
>> ---------------------------------------
>> Sent from YesSoftware forum
>> http://forums.codecharge.com/
>>
>
>
|
|
|
 |
feha
Posts: 712
|
| Posted: 03/06/2008, 1:06 AM |
|
If you need to find number of days in current month:
$days_in_month = cal_days_in_month(CAL_GREGORIAN, date("m",time()), date("Y",time()));
for this february would give you 29 days.
next year 28 days
_________________
Regards
feha
www.vision.to
feedpixel.com |
 |
 |
datadoit
|
| Posted: 03/06/2008, 6:06 AM |
|
Now ain't that just the cat's meow!
|
|
|
 |
feha
Posts: 712
|
| Posted: 03/07/2008, 10:17 AM |
|
Sorry
I had some code of my time class that will not work standalone so I deleted it ...
_________________
Regards
feha
www.vision.to
feedpixel.com |
 |
 |
wkempees
|
| Posted: 03/07/2008, 11:51 AM |
|
Do you really want the Cat's meow:
$days_in_month = CCDaysInMonth(date("Y", time()), date("m", time()))
I in Common.php as is....... no global definition no hassle.
"feha" <feha@forum.codecharge> schreef in bericht
news:547d186b1110d9@news.codecharge.com...
> Sorry
> I had some code of my time class that will not work standalone so I
> deleted it
> ..
> _________________
> Regards
> feha
> Vision.To Design
> www.vision.to
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
wkempees
|
| Posted: 03/07/2008, 11:53 AM |
|
//CCDaysInMonth @0-4DFC9A98
function CCDaysInMonth($year, $month) {
switch ($month) {
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
if ($year % 4)
return 28;
elseif ($year % 100)
return 29;
elseif ($year % 400)
return 28;
else return 29;
default:
return 31;
}
|
|
|
 |
datadoit
|
| Posted: 03/08/2008, 6:23 PM |
|
I am standing here beside myself. :)
|
|
|
 |
wkempees
|
| Posted: 03/09/2008, 4:22 PM |
|

We are here to learn from eachother!
Thanks for all everyone has given me over time.
Walter
"datadoit" <datadoit@forum.codecharge> schreef in bericht
news:fqvhnm$fqn$1@news.codecharge.com...
>I am standing here beside myself. :)
|
|
|
 |