Jump to content

[SOLVED] incrementing numbers within select tags


webguync

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

 

 

 

 

Link to comment
Share on other sites

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.

} 
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.