[SOLVED] Code works, but can it be reduce? or improved?
Posted: Wed Sep 15, 2004 3:50 pm
After researching and figuring things out, I came up with the solution on how to do what I wanted. Yet, some how I think the code can be change to be simpler or more efficient, maybe a function or a better selection of code.
So if anybody can help me reduce this code to something simpler I will appreciate it. One thing that I my post somewhere else is that some how my first row from my mysql_array is not displaying, so my file_id=1 never shows.. Don't know why but it just doesn't.
ok here is my code
and here is some of the code of my HTML form in tables
So if anybody can help me reduce this code to something simpler I will appreciate it. One thing that I my post somewhere else is that some how my first row from my mysql_array is not displaying, so my file_id=1 never shows.. Don't know why but it just doesn't.
ok here is my code
Code: Select all
<?php
require_once ('mysql_connect.php');
$query = "SELECT file_id, file_date FROM uploads";
$result = mysql_query($query);
$rows = mysql_fetch_array($result);
$pulldown = "<option selected>Select one</option>\n";
$jan = $pulldown;
$feb = $pulldown;
$mar = $pulldown;
$apr = $pulldown;
$may = $pulldown;
$jun = $pulldown;
$jul = $pulldown;
$aug = $pulldown;
$sep = $pulldown;
$oct = $pulldown;
$nov = $pulldown;
$dic = $pulldown;
while ($rows = mysql_fetch_array($result)) {
$date = $rows['file_date'];
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
if ($regs[2] == 1) {
$jan .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 2) {
$feb .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 3) {
$mar .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 4) {
$apr .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 5) {
$may .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 6) {
$jun .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 7) {
$jul .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == {
$aug .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 9) {
$sep .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 10) {
$oct .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 11) {
$nov .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
if ($regs[2] == 12) {
$dec .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
}
} else {
echo "Invalid date format: $date";
}
}
?>Code: Select all
<td>January<br>
<select name="select" onChange="MM_jumpMenu('parent',this,0)"><?php echo $jan ?></select></td>
<td>February<br>
<select name="select" onChange="MM_jumpMenu('parent',this,0)"><?php echo $feb ?></select></td>
<td>March<br>
<select name="select" onChange="MM_jumpMenu('parent',this,0)"><?php echo $mar ?> </select></td>
</tr>
<tr align="center">
<td>April<br>
<select name="select" onChange="MM_jumpMenu('parent',this,0)"><?php echo $apr ?></select></td>
<td>May<br>
<select name="select" onChange="MM_jumpMenu('parent',this,0)"><?php echo $may ?></select></td>
<td>June<br>
<select name="select" onChange="MM_jumpMenu('parent',this,0)"><?php echo $jun ?></select></td>