webguync Posted June 16, 2007 Share Posted June 16, 2007 Hello I need to create an HTML select tag and add the days of the month from 1-31. <select> <option value ="1">1</option> <option value ="2">2</option> <option value ="3">3</option> <option value ="4">4</option> </select> etc... like that except I wanted to use php to programitically create the 1-31 instead of adding each option, and I need help with that part. If someone could point me in the right direction, I would greatly appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/55833-solved-incrementing-numbers-within-select-tags/ Share on other sites More sharing options...
chigley Posted June 16, 2007 Share Posted June 16, 2007 <?php echo "<select>\n"; for($i = 1; $i <= 31; $i++) { echo "\t<option value=\"{$i}\">{$i}</option>\n"; } echo "</select>"; ?> Untested. } Quote Link to comment https://forums.phpfreaks.com/topic/55833-solved-incrementing-numbers-within-select-tags/#findComment-275815 Share on other sites More sharing options...
webguync Posted June 16, 2007 Author Share Posted June 16, 2007 thanks, that worked as intended one more question, I want to do the same thing (more or less), but I want to display 1980-2007 with 2007 being at the top and 1980 at the bottom. I know it would be quite similar, but need some assistance thanks gain Quote Link to comment https://forums.phpfreaks.com/topic/55833-solved-incrementing-numbers-within-select-tags/#findComment-275823 Share on other sites More sharing options...
chigley Posted June 16, 2007 Share Posted June 16, 2007 <?php echo "<select>\n"; for($i = 2007; $i >= 1980; $i--) { echo "\t<option name=\"{$i}\">{$i}</option>\n"; } echo "</select>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55833-solved-incrementing-numbers-within-select-tags/#findComment-275824 Share on other sites More sharing options...
webguync Posted June 16, 2007 Author Share Posted June 16, 2007 that did the trick, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/55833-solved-incrementing-numbers-within-select-tags/#findComment-275839 Share on other sites More sharing options...
taith Posted June 16, 2007 Share Posted June 16, 2007 just to keep it current... switch 2007... with date(Y)... so you never have to go back and change it ;-) Quote Link to comment https://forums.phpfreaks.com/topic/55833-solved-incrementing-numbers-within-select-tags/#findComment-275844 Share on other sites More sharing options...
redarrow Posted June 16, 2007 Share Posted June 16, 2007 not tested ok. <?php // set the post $day=$_POST['day']; $month=$_POST['month']; $year=$_POST['year']; ?> <?php // convert result as one using caternation $result=$day.$month.$year; // if set post submit. if(isset($_POST['submit'])){ // if url condition are meet. if($_GET['cmd']=="go"){ // show results. echo $result; } } ?> <form action="<?php $_SERVER['PHP_SELF']; ?>?cmd=go" method="POST"> Day <br> <select name="day"> <?php for($i = 1; $i <= 31; $i++) { echo "<option value='$i'>$i</option>"; } ?> </select> <br> Month <br> <select name="month"> <?php $m=array("jan","feb","mar","apr","may","jun", "jul","aug","sep","oct","nov","dec"); foreach($m as $month){ echo "<option value='$month'>$month</option>"; } ?> </select> <br> Year <br> <select name="year"> <?php $y=range(2007,2020); foreach($y as $year){ echo "<option value='$year'>$year</option>"; } ?> </select> <br> please select a date <br> <input name="submit" type="submit" value="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/55833-solved-incrementing-numbers-within-select-tags/#findComment-275850 Share on other sites More sharing options...
redarrow Posted June 16, 2007 Share Posted June 16, 2007 There you go a little test for your database ok. <?php //database connection. if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 1; $from = (($page * $max_results) - $max_results); //database query. $query="select * from what_ever DESC LIMIT $from, $max_results "; $result=mysql_query($query); while($rec=mysql_fetch_assoc($result)){ $point_query="select * from blogs where what_ever='what_evrer' "; $point_result=mysql_query($point_query)or die(mysql_error()); while($p=mysql_fetch_assoc($point_result)){ // show the information } $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM what_ever"),0); if($page > 1){ $prev = ($page - 1); echo "<div align='center'><a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Prev</a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "<font color='yellow'>$i</font> "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\"></a> "; } } if($page < $total_pages){ $next = ($page + 1); // show other infomation. } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55833-solved-incrementing-numbers-within-select-tags/#findComment-275858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.