[SOLVED] Code works, but can it be reduce? or improved?
Moderator: General Moderators
Code: Select all
<?php
$query = "SELECT file_id, DATE_FORMAT(file_date, '%Y %c %e') AS fd FROM uploads";
$result = mysql_query($query);
$rows = mysql_fetch_array($result);
$pulldown = "<option selected>Select one</option>\n";
$mes = array(1=>'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
for($i=1; $i<count($mes)+1; $i++)
$mes[$i] = $pulldown;
while ($rows = mysql_fetch_array($result)) {
$date = $rows['fd'];
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
$mes[$regs[2]] .="<option value = "download_file.php?uid={$rows['file_id']}">$regs[3]</option>\n";
} else {
echo "Invalid date format: $date";
}
}
?>
Last edited by paquin1 on Thu Sep 16, 2004 9:46 am, edited 1 time in total.
Code: Select all
<?php
$resultQ = mysql_query($resultSQL);
while($row = mysql_fetch_object($resultQ))
$list[count($list)] = $row;
print_r($list);
?>by the way, are you using MSSQL and IIS for php?
change you code to
because I was just getting errors... and commented all of my PHP
and this is what I get on the screen
and I'm using MySQL and IIS to test and than I uploaded to a MySQL and linux server.
Code: Select all
<?php
$query = "SELECT file_id, DATE_FORMAT(file_date, '%Y-%c-%e') AS fd FROM uploads";
//$result = mysql_query($query);
$resultQ = mysql_query($query);
while($row = mysql_fetch_object($resultQ))
$list[count($list)] = $row;
print_r($list);
?>and this is what I get on the screen
Code: Select all
Notice: Undefined variable: list in c:\inetpub\wwwroot\test.php on line 34
Array ( ї0] => stdClass Object ( їfile_id] => 1 їfd] => 2004-1-20 ) ї1] => stdClass Object ( їfile_id] => 2 їfd] => 2004-5-10 ) ї2] => stdClass Object ( їfile_id] => 3 їfd] => 2004-1-30 ) ї3] => stdClass Object ( їfile_id] => 4 їfd] => 2004-10-13 ) )- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
undefined variable means that youy havn't properly set the variable before you are trying to use it
good way to do it
bad way
good way to do it
Code: Select all
<?php
$int = 'blah';
if ($int == 5)
echo '5';
else
echo 'no var';
?>Code: Select all
<?php
if ($int == 5)
echo '5';
else
echo 'no var';
?>