Solved

how to bring in list box combining html & php?

Posted on 2002-06-04
7
230 Views
Last Modified: 2008-03-17
hai all,
my html file has foll coding, the file saved as php.
I try to get list box using foll coding.But from option 10 it uses php to list it down.but I get only until 9. it cannot go beyond 10.Can anyone tell me where I went wrong & provide me the solution

<?php
?>
//some html codes
<td align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<select name="gd1"size="1" onFocus="selfclick(2)">
                <option value="01">1</option>
                <option value="02">2</option>
                <option value="03">3</option>
                <option value="04">4</option>
                <option value="05">5</option>
                <option value="06">6</option>
                <option value="07">7</option>
                <option value="08">8</option>
                <option value="09">9</option>
                <?
                 for ($i=10;$i<=31;$i++)
                 echo("<option value=".$i.">".$i."</option>");
?>
              </select>
              </font> </td>
0
Comment
Question by:baska
7 Comments
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7053408
Check this,

<?php
?>
//some html codes
<td align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<select name="gd1"size="1" onFocus="selfclick(2)">
               <option value="01">1</option>
               <option value="02">2</option>
               <option value="03">3</option>
               <option value="04">4</option>
               <option value="05">5</option>
               <option value="06">6</option>
               <option value="07">7</option>
               <option value="08">8</option>
               <option value="09">9</option>
               <?
                for ($i=10;$i<=31;$i++)
                    {
                         print "<option value=\"$i\">$i</option>";
                    }

?>

JD
0
 
LVL 5

Accepted Solution

by:
dkjariwala earned 50 total points
ID: 7053410
Btw, you can just make it simple by doing,

<?php
?>
//some html codes
<td align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<select name="gd1"size="1" onFocus="selfclick(2)">

               <?
                for ($i=1;$i<=31;$i++)
                    {
                         if($i<10)
                              $value = "0" . $i;
                         else
                              $value = $i;
                         print "<option value=\"$value\">$i</option>\n";
                    }

?>



JD
0
 
LVL 32

Expert Comment

by:Batalf
ID: 7053551
or simply:

<?php
?>
//some html codes
<td align="center"><font face="Arial, Helvetica, sans-serif" size="2">
<select name="gd1"size="1" onFocus="selfclick(2)">
               <?
                for ($i=1;$i<=31;$i++)
{
  if($i<10)$prefix="0";else $prefix="";
                echo("<option value=\"".$prefix$i."\">".$i."</option>");

}?>
             </select>
             </font> </td>
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 32

Expert Comment

by:Batalf
ID: 7053552
Sorry dkjariwala : Caching problem on my PC I guess. Didn't see your last comment.
0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7053562
NP.

JD
0
 
LVL 5

Expert Comment

by:Hamlet081299
ID: 7055052
I think dkjariwala has already answer the question, but just one slight improvement I would suggest is to replace...

                        if($i<10)
                             $value = "0" . $i;
                        else
                             $value = $i;

... with ...
                        $value = sprintf('%02d', $i);



Also as a side note.... I'm guessing that maybe this is something to do with giving the user a way to select a date.  If that's the case I suggest you check out the PEAR Calendar functions, there's some really handy functions that make date handling much easier.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 7055826
Can you try changing the value in the size option on the Select tag to 2?

Regards,

Richard.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now