Page 2 of 3

Posted: Thu Sep 16, 2004 9:21 am
by dethron
can you send the dump schema of the db?

Posted: Thu Sep 16, 2004 9:26 am
by paquin1
hold on I need to format my date coming from my db, cause right now the months come out like 01, 02, 03....

Posted: Thu Sep 16, 2004 9:33 am
by dethron
wa'in

Posted: Thu Sep 16, 2004 9:35 am
by paquin1

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";
		}
}
?>
I get no errors now but it jumps to the else Invalid date format: $date

Posted: Thu Sep 16, 2004 9:37 am
by dethron
dont forget $$ on line 13

Posted: Thu Sep 16, 2004 9:40 am
by dethron
$$mes[$regs[2]]
here, assume $regs[2] given us as 10,
then,

$$mes[10] becomes $oct

then you expect

$oct is "<option selected>Select one</option>\n<option value = \"download_file.php?uid={$rows['news_id']}\">$regs[3]</option>\n";

Posted: Thu Sep 16, 2004 9:42 am
by paquin1
ok I got it not to jump to the else statement, by adding hyphens to my mysql '%Y-%c-%e', but if I add the extra $ to line 13 y get this error now..
Notice: Undefined variable: Select one in c:\inetpub\wwwroot\test.php on line 43 line 43 being line 13 of last code

Posted: Thu Sep 16, 2004 9:43 am
by paquin1
no extra $ gives me no erros but also no data

Posted: Thu Sep 16, 2004 9:45 am
by paquin1
should I also change somethig in my tables with my pulldown menus?

Posted: Thu Sep 16, 2004 9:49 am
by dethron
paste here the db dump schema, and so i can finish it :)

Posted: Thu Sep 16, 2004 9:51 am
by paquin1
how do I do that?

Posted: Thu Sep 16, 2004 9:56 am
by dethron

Code: Select all

<?php
$resultQ = mysql_query($resultSQL);
	
while($row = mysql_fetch_object($resultQ))
	$list[count($list)] = $row;

print_r($list);
?>
replace line 4 with the code above, and tell me what you see on your screen?

by the way, are you using MSSQL and IIS for php?

Posted: Thu Sep 16, 2004 10:08 am
by paquin1
change you code to

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);

?>
because I was just getting errors... and commented all of my PHP

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 ( &#1111;0] =&gt; stdClass Object ( &#1111;file_id] =&gt; 1 &#1111;fd] =&gt; 2004-1-20 ) &#1111;1] =&gt; stdClass Object ( &#1111;file_id] =&gt; 2 &#1111;fd] =&gt; 2004-5-10 ) &#1111;2] =&gt; stdClass Object ( &#1111;file_id] =&gt; 3 &#1111;fd] =&gt; 2004-1-30 ) &#1111;3] =&gt; stdClass Object ( &#1111;file_id] =&gt; 4 &#1111;fd] =&gt; 2004-10-13 ) )
and I'm using MySQL and IIS to test and than I uploaded to a MySQL and linux server.

Posted: Thu Sep 16, 2004 10:10 am
by dethron
thanx now, give some time :) just sit, and relax :)

Posted: Thu Sep 16, 2004 10:12 am
by John Cartwright
undefined variable means that youy havn't properly set the variable before you are trying to use it

good way to do it

Code: Select all

<?php

$int = 'blah';

if ($int == 5) 
echo '5';
else 
echo 'no var';


?>
bad way

Code: Select all

<?php

if ($int == 5) 
echo '5';
else 
echo 'no var';


?>