Well, here's the long way of doing it that I ended up using! For my
'tournament' date (for a football web site) I have three stored values:
$tournamentDay, $tournamentMonth, $tournamentYear which are evaluated for each
drop-down.

I might work on a neater solution actually!

Cheers
Richard

<tr>
<th>Tournament Date : </th>
<td><select name="tournamentDay">
<option></option>
<?php
  for ($i = 1; $i <= 31; $i++)
  {
    $day = sprintf("%02d", $i);
    if ("$day" == "$tournamentDay")
    {
      echo("<option selected>$day</option>\n");
    }
    else
    {
      echo("<option>$day</option>\n");
    }
  }
?>
</select>
<select name="tournamentMonth">
<option></option>
<?php
  $months = array("", "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December");

  for ($i = 1; $i <= 12; $i++)
  {
    $month = sprintf("%02d", $i);
    if ("$month" == $tournamentMonth)
    {
      echo("<option value=\"$month\" selected>" . $months[$i] . "</option>");
    }
    else
    {
      echo("<option value=\"$month\">" . $months[$i] . "</option>");
    }
  }
?>
</select>
<select name="tournamentYear">
<option></option>
<?php
  for ($i = 2001; $i <= 2005; $i++)
  {
    if ($i == $tournamentYear)
    {
      echo("<option selected>$i</option>\n");
    }
    else
    {
      echo("<option>$i</option>\n");
    }
  }
?>
</select>
</td>
</tr>

-----Original Message-----
From: Andy B [mailto:[EMAIL PROTECTED]
Sent: 07 April 2004 07:38
To: [EMAIL PROTECTED]
Subject: [PHP] php and drop down boxes


hi...

i have a few things i need and dont know where to go to get some
ideas/examples of how to do some things:

1. i need to know how to take info from a mysql db load it into a dropdown
box and then select as the default choice whatever value was in the db: i.e.
i have a combo box with the month/year. the drop down boxes option values
for the month and year are numbers: for the month 1-12 and for the year:
2004-2038. now when lets say i have the variables: $edit['Month'] and
$edit[Year'] which hold month/year values from the db...now how would i make
those variables the default select choice in the combo boxes??
2. i need to make a combo box of jan-dec and view all. the values for the
drop down box will be 1-12 and 0 (0 is for view all). now the combo box will
need to go to a db search for all relevant records on the month selected and
show them on a page (the only catche is the combo box needs to be visible on
all pages)...

anybody know where i can go to find out how to do all of this??

any searches i tried to do all come back with loading dynamic content into a
box but i dont need that...they never talk about making a default "selected"
state with php and stuff...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


==============================================================================
This message is for the sole use of the intended recipient. If you received
this message in error please delete it and notify us. If this message was
misdirected, CSFB does not waive any confidentiality or privilege. CSFB
retains and monitors electronic communications sent through its network.
Instructions transmitted over this system are not binding on CSFB until they
are confirmed by us. Message transmission is not guaranteed to be secure.
==============================================================================

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to