Hello All,
Kind of new to PHP. I have an html form where a person inputs a date via
a drop down select. How do I make php put a zero in front of the numbers
1-9 ie. 01 02 03 when writing to the file? I have tried making the
value="01" etc. but this doesn't work. Below is a snippet of my form and
the code I am using to write to the file. I hope I have made myself
clear enough. Your help is greatly appreciated.
//form part
<select class="inform" name="logday">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
etc,
//code part
fputs($out,"$_POST[logday] ");
Thanks,
Patrick
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science http://ocgweb.marine.usf.edu Phone: 727 553-3334
The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld 6 3957
Patrick wrote: Hello All,
Kind of new to PHP. I have an html form where a person inputs a date via a drop down select. How do I make php put a zero in front of the numbers 1-9 ie. 01 02 03 when writing to the file? I have tried making the value="01" etc. but this doesn't work. Below is a snippet of my form and the code I am using to write to the file. I hope I have made myself clear enough. Your help is greatly appreciated.
//form part <select class="inform" name="logday"> <option value="1">1 <option value="2">2 <option value="3">3 <option value="4">4 <option value="5">5 <option value="6">6 <option value="7">7 <option value="8">8 <option value="9">9 <option value="10">10 etc,
//code part fputs($out,"$_POST[logday] ");
use something more like:
fputs($out,sprintf('%02d',intval($_POST['logday'])));
Carved in mystic runes upon the very living rock, the last words of
Patrick of comp.lang.php make plain: Kind of new to PHP. I have an html form where a person inputs a date via a drop down select. How do I make php put a zero in front of the numbers 1-9 ie. 01 02 03 when writing to the file? I have tried making the value="01" etc. but this doesn't work.
Unless you're doing something in your code to explicitly change the type
of $logday to numerical, there's no reason that zero-padding in the
VALUE attribute shouldn't work.
<?php
$x = '01';
echo $x;
?>
Outputs 01
<?php
$x = '01';
$x*= 1;
echo $x;
?>
Outputs 1
--
Alan Little
Phorm PHP Form Processor http://www.phorm.com/
Patrick wrote: Hello All,
Kind of new to PHP. I have an html form where a person inputs a date via a drop down select. How do I make php put a zero in front of the numbers 1-9 ie. 01 02 03 when writing to the file? I have tried making the value="01" etc. but this doesn't work. Below is a snippet of my form and the code I am using to write to the file. I hope I have made myself clear enough. Your help is greatly appreciated.
//form part <select class="inform" name="logday"> <option value="1">1 <option value="2">2 <option value="3">3 <option value="4">4 <option value="5">5 <option value="6">6 <option value="7">7 <option value="8">8 <option value="9">9 <option value="10">10 etc,
//code part fputs($out,"$_POST[logday] ");
Thanks, Patrick
I figured it out.
$logday = $_POST[logday];
and then
fprintf($out,"%02d",$logday);
instead of the fputs, which gives me my leading zero.
Patrick
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science http://ocgweb.marine.usf.edu Phone: 727 553-3334
The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
Use this
<?
for ($i==1;$i<= 31;$i++)
{
if ($i < 10)
{
?>
<option value="<? echo $i; ?>"> 0<? echo $i; ?> </option>
<? } else { ?>
<option value="<? echo $i; ?>"> <? echo $i; ?> </option>
<?
}
}
?>
Enjoy it
omanzi
Justin Koivisto wrote: Patrick wrote: Hello All,
Kind of new to PHP. I have an html form where a person inputs a date via a drop down select. How do I make php put a zero in front of the numbers 1-9 ie. 01 02 03 when writing to the file? I have tried making the value="01" etc. but this doesn't work. Below is a snippet of my form and the code I am using to write to the file. I hope I have made myself clear enough. Your help is greatly appreciated.
//form part <select class="inform" name="logday"> <option value="1">1 <option value="2">2 <option value="3">3 <option value="4">4 <option value="5">5 <option value="6">6 <option value="7">7 <option value="8">8 <option value="9">9 <option value="10">10 etc,
//code part fputs($out,"$_POST[logday] ");
use something more like: fputs($out,sprintf('%02d',intval($_POST['logday'])));
or
fprintf($out, '%02d', $_POST['logday']);
Also, for kicks, the form part could be:
<select class="inform" name="logday">
<?php
foreach( range(1, 10) as $v ) {
printf("<option value="%d">%d</option>\n", $v);
}
?>
-david-
David Haynes wrote:
Typed too fast, correction below: fprintf($out, '%02d', $_POST['logday']);
Also, for kicks, the form part could be:
<select class="inform" name="logday"> <?php foreach( range(1, 10) as $v ) { printf("<option value="%d">%d</option>\n", $v);
printf("<option value=\"%02d\">%d</option>\n", $v); } ?>
-david- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: LRW |
last post by:
This may be a question more directed to Excel, but I'm using PHP to
generate a CSV to be imported into Excel, so maybe the solution is
there. So, sorry for crossposting.
Anyway, I'm generating a...
|
by: david |
last post by:
Hi,
I have an application as follows:
MySQL database Back-Eend linked to MS Access Front-End and ASP Web
Application.
I require users to enter Serial Numbers such as:
0105123567 (10...
|
by: stu_gots |
last post by:
I have been losing sleep over this puzzle, and I'm convinced my train
of thought is heading in the wrong direction. It is difficult to
explain my circumstances, so I will present an identical...
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
...
|
by: Melissa Kay Beeline |
last post by:
OK, here's the sitch : we have an access control system at work that
registers ever entry/exit of every employee. I recently made some
queries in Access so the ppl in HR could make reports (who...
|
by: Sivarn |
last post by:
I'm writing a program for that takes dates as input using scanf. I
want to verify that the user is inputting a full 4 digits for the
year. How do I do this? I know that the return value on printf...
|
by: comp_novice |
last post by:
I need to control the number of digits to be printed after the
exponential. Please have a look at the example below:
float fVal = 0.06854344
The printf that I am using is
fprintf(pfile,...
|
by: Rahul |
last post by:
Hi Everybody
I have some problem in my script. please help me. This is script file.
I have one *.inq file. I want run this script in XML files. But this
script errors shows . If u want i am...
|
by: Jo |
last post by:
Hi there,
I'm Jo and it's the first time I've posted here. I'm in process of creating
a database at work and have come a little unstuck.....I'm a bit of a novice
and wondered if anyone could...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |