Try this:

<<< BEGIN:PHP-CODE >>>

$result = mysql_query ("SELECT DISTINCT date FROM linktracker WHERE name
LIKE '$PHP_AUTH_USER' GROUP BY date ORDER BY date");
if (mysql_num_rows($result))
{
  for($i=0;$i<count($row);$i++)
  {
    $date = array(
                  "begin" => array($i => $row["date"]),
                  "end" => array($i => $row["date"])
                  );
  }
} else {
  print ("Sorry, no record were found.");
}

function drawSelect($which)
{
  global $date;
  foreach($date[$which] AS $date_begin)
  {
    ?>
    <option value="<?=$date_begin?>"><?=$date_begin?></option>
    <?
  }

}

?>
<table>
  <tr>
    <td>Begindate</td>
    <td>Enddate</td>
  </tr>
  <tr>
    <td><form method="post" action="index.php" name="date_select">
        <input type="hidden" name="action" value="date_select">
        <select name="date_begin">
<?
drawSelect("begin");
?>
        </select>
    </td>
    <td><select name="date_end">
<?
rsort($date[end]);

drawSelect("end");
?>
        </select>
    </td>
  </tr>
  <tr>
    <td colspan="2"><input type="submit" name="Submit"
value="Submit"></form></td>
  </tr></table>

<<< END:PHP-CODE >>>

btw - you need to watch your closing '>'  you are missing a few.  Plus to
get distince to work right you need to use the "GROUP BY" clause.

Jim

----- Original Message -----
From: "Bart Verbeek" <[EMAIL PROTECTED]>
To: "Php-General-list" <[EMAIL PROTECTED]>; "PHP-DB mailinglist"
<[EMAIL PROTECTED]>
Sent: Wednesday, October 24, 2001 12:23 PM
Subject: [PHP-DB] array-problems


> Hello,
> Can anyone help me with this script I'm using?
>
> I've saved dates in a database and want to make two select-lists of these
> dates in a html-form.
> I want to select each unique date one time (no doubles).
> List 1 is used to set the begin-date of the query for the report, List 2
> will
> set the end-date and must be reversed.
> When the form is processed the data selected between the begin-date and
the
> end-date has to be show.
>
> I can't seem to get my code to work: the select-lists stay empty after
> processing the code below.
>
> Can anyone help? Tips...
>
> regards,
>
> Bart
>
>
> <<< BEGIN:PHP-CODE >>>
> $i=0;
>  $result = mysql_query ("SELECT DISTINCT date FROM linktracker WHERE name
> LIKE '$PHP_AUTH_USER' ORDER BY date");
>  if ($row = mysql_fetch_array($result)) {
>         do {
>           $date = array(
>                 "begin" => array($i => $row["date"]),
>                 "end" => array($i => $row["date"])
>                 );
>         $i++;
>         } while ($row = mysql_fetch_array($result));
>  } else {print ("Sorry, no record were found.");
>  } //end else $result
>
>         print("<table><tr><td>Begindate</td<td>Enddate</td></tr>\n".
>                 "<tr><td><form method=\"post\" action=\"index.php\"
> name=\"date_select\">".
>                 "<input type=\"hidden\" name=\"action\"
> value=\"date_select\">".
>                 "<select name=\"date_begin\">");
>
>         while (list($key, $date_begin) = each($date[begin])) {
>     echo "<option value=\"".$date_begin  ."\">" . $date_begin .
> "</option>\n";
>         }
>
>         print("</select></td><td><select name=\"date_end\">");
>
>         rsort($date[end]);
>
>         while (list($key, $date_end) = each($date[end])) {
>           echo "<option value=\"".$date_end  ."\">" . $date_end .
> "</option>\n";
>         }
>
>         print("</select></td></tr>\n<tr><td colspan=\"2\">".
>               "<input type=\"submit\" name=\"Submit\" value=\"Submit\">".
>               "</form></td></tr</table>");
>
>         mysql_free_result ($result);
>         mysql_close();
> <<< END:PHP-CODE >>>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to