473,787 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stumped with select function

I have a function that creates a select list:

function make_select_ns( $name,$array,$p ersist){
$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($pers ist)){$selected =
"selected"; }
else {$selected = "";}
$string .= "<option $selected value='" .
str_pad($value, 2,"0",STR_PAD_L EFT) . "'>$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 1400


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

function make_select_ns( $name,$array,$p ersist){
$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($pers ist)){$selected =
"selected"; }
else {$selected = "";}
$string .= "<option $selected value='" .
str_pad($value, 2,"0",STR_PAD_L EFT) . "'>$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($a rray); // to remove duplicates
$my_select =& $f->addElement('se lect', 'my_name', 'Select me:', $array);
$my_select->setSelected($s elected)
$f->addElement('su bmit',null,'Sub mit');
// 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
2713
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2: The name of the second array $formField1CompareWith: String to use as my comparison basis for first array. Defaults to using $val unless it's 'key' $formField2CompareWith: String to use as my comparison basis for second array. Same default as...
10
3181
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 <input type="button" onClick="OutputData()"> The OutputData() function is a javascript function that simply does this: window.location = "Page1.asp?Flag=1";
1
1469
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 to be added to the source document and have the XSLT copy them over without explicitly adding them to the XSL file. My problem is that when I run the transformation in XmlSpy, I just get back the text of all the nodes, and not the xml tags plus...
2
2886
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 xmlns="urn:oasis:names:tc:DSML:2:0:core" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <searchResponse requestID="9"> <searchResultEntry dn="cn=Larry Simmons,ou=People,o=Morrison Industries,c=US"...
0
1239
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 database. The data adapter configuration wizard generates both insert, and select statements, but on the final page of the wizard it says that update, and delete statements could not be generated. The reason that Im given for this happeneing is "could...
2
2277
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 used DLookup several times and I've actually re-created the same lookup just in different forms. Here's my problem. I'm using dlookup when I enter a part description it adds the part number for me. I choose the part description from a combo...
2
3870
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 scan utility, which can be used to default and change the ip of units. A quick example, say your on a network of 192.168.100.0. You obviously wont be able to comminicate with our unit on your network if the units ip is 206.71.186.46. The scan...
4
1470
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> <Item Value="A" Id="1" Count="1"/> <Item Value="B" Id="2" Count="1"/>
4
1868
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 a stored procedure which nests itself within itself and uses a temporary table to store the data while writing. The nested stored procedure is used so that it can output the data rows in a db table into an organized tree like Example 1 1.0...
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.