?
Solved

how to bring in list box combining html & php?

Posted on 2002-06-04
7
Medium Priority
?
239 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

762 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