472,992 Members | 3,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

Stumped with select function

I have a function that creates a select list:

function make_select_ns($name,$array,$persist){
$string = "<select name=\"$name\">";
$string .="<option selected>" . ucfirst($name) . "</option>\n";
if ($name == $array[0]){array_shift($array);} //removes duplicate when
table name equals 1st item in array
foreach ($array AS $value) {
if (($value == $persist) && is_string($persist)){$selected =
"selected";}
else {$selected = "";}
$string .= "<option $selected value='" .
str_pad($value,2,"0",STR_PAD_LEFT) . "'>$value</option>\n";
}
$string.="</select>";
print $string;
}

I have arrays for Months, Days, Years, Hours, and Minutes.

All of the arrays work as expected except for the minutes array which
starts at 0 and goes to 55 in increments of 5. Whenever this loads
after a post the value 0 is selected. What am I missing here? Why
does the zero seem to be causing me problems?

Let me know if you need more information.

Thanks,

-Mark

Aug 30 '05 #1
1 1361


supline wrote:
I have a function that creates a select list:

function make_select_ns($name,$array,$persist){
$string = "<select name=\"$name\">";
$string .="<option selected>" . ucfirst($name) . "</option>\n";
if ($name == $array[0]){array_shift($array);} //removes duplicate when
table name equals 1st item in array
foreach ($array AS $value) {
if (($value == $persist) && is_string($persist)){$selected =
"selected";}
else {$selected = "";}
$string .= "<option $selected value='" .
str_pad($value,2,"0",STR_PAD_LEFT) . "'>$value</option>\n";
}
$string.="</select>";
print $string;
}

I have arrays for Months, Days, Years, Hours, and Minutes.

All of the arrays work as expected except for the minutes array which
starts at 0 and goes to 55 in increments of 5. Whenever this loads
after a post the value 0 is selected. What am I missing here? Why
does the zero seem to be causing me problems?

Let me know if you need more information.


Alternative solution (with PEAR):

$f = new HTML_QuickForm('life_is_simple');

// assuming $array contains our selections and $selected is
// an array of selected values
$array = array_unique($array); // to remove duplicates
$my_select =& $f->addElement('select', 'my_name', 'Select me:', $array);
$my_select->setSelected($selected)
$f->addElement('submit',null,'Submit');
// or some othe way of displaying it
$f->display();

// end

//Marcin
Aug 30 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2:...
10
by: Manny | last post by:
I have a web form "Page1.asp" and it reads data from a database, does some calculations, and displays the records in pages. Works fine. I have a button that displays on the page, defined as...
1
by: PBR | last post by:
Hi, I'm trying to do some grouping on a set elements based on one of the set's child element values. That seems to work OK. My problem is that I would like to allow for additional child elements...
2
by: awilliam | last post by:
I'm using the BIE workflow engine and after querying an LDAP DSA I need to transform the XML response, which looks like - <?xml version="1.0" encoding="UTF-8" ?> <batchResponse...
0
by: Vince Campanile | last post by:
Ive got what must bea very basic question, but its got ne thouroughly stumped. Im writing a very simple application in Visual Basic.Ne 2003, thats using a data adapter hooked up to an Access...
2
by: Don | last post by:
Can someone help me fix my DLookup problem. I'm far from proficiency with Access. I've been creating databases for several years for work with the help of many of you and trial and error. I have...
2
by: Ashaman0 | last post by:
ok ill start off with a little background. I work for a company which makes heavy duty wireless routers/bridges, which work over long distances. Up to 30miles. Now each of our units comes with a...
4
by: J | last post by:
I've spent most of the day on this, and I just can't seem to find a solution, please help me! :) I'm recieving XML that I can't modify that looks like: <?xml version="1.0"?> <Doc> <Page>...
4
by: davinski | last post by:
Hello, it's been a while since my last post, hope everyone is fine :P I'm stuck with what seems to be a simple task, but I'm getting confused on how to complete this. Basically, I have been given...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.