Solved

how to bring in list box combining html & php?

Posted on 2002-06-04
7
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:Richard Quadling
ID: 7055826
Can you try changing the value in the size option on the Select tag to 2?

Regards,

Richard.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 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