?
Solved

how to bring in list box combining html & php?

Posted on 2002-06-04
7
Medium Priority
?
241 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 150 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
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!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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