Forum Moderators: coopster
parse error, unexpected T_STRING, expecting ',' or ';'
Heres more of the code i'm displaying
echo '<table class="table" width="100%">';
echo '<tr>';
while ($row = $connector->fetchArray($result))
{
echo '<tr><td width="15">';
echo $row['ID'];
echo '</td>';
echo '<td width="45">';
echo 'date("m/d/y",mktime $row['datetime']';
echo '</td>';
echo '<td width="45">';
echo $row['firstname']," ", $row['lastname'];
echo '</td>';
echo '<td width="45">';
echo $row['email'];
echo '</td>';
echo '</td></tr>';
}
echo '</table>';
echo date("m/d/y",mktime $row['datetime'];
On another note, you could also use the database-specific Date/Time functions to format during SELECTion rather than format afterward using PHP. For example, in MySQL you could ...
SELECT DATE_FORMAT(timestamp_field, '%m/%d/%y') FROM table;
parse error, unexpected T_VARIABLE
Doesn't the date function need a $ sign before it?
i.e. - echo $date("m/d/y",mktime $row['datetime']);
here is the edited code i got the parse error with:
echo '<table class="table" width="100%">';
echo '<tr>';
while ($row = $connector->fetchArray($result))
{
echo '<tr><td width="15">';
echo $row['ID'];
echo '</td>';
echo '<td width="45">';
echo date("m/d/y",mktime $row['datetime']);
echo '</td>';
echo '<td width="45">';
echo $row['firstname']," ", $row['lastname'];
echo '</td>';
echo '<td width="45">';
echo $row['email'];
echo '</td>';
echo '</td></tr>';
}
echo '</table>';
Changing the format in mysql didn't work either - and it may be useful to display the date and time in that field sometime down the road - so that might not be the best solution for me.
Changing the format in mysql didn't work either -
Yes, it will. You must have something else incorrect. Even if you do think that it may be useful to display the date and time in that field sometime down the road, you can still return that field as well. You just select it as is as well as the formatted version. Something like
SELECT timestamp_field, DATE_FORMAT(timestamp_field, '%m/%d/%y') AS mmddyy FROM table;
function func_change_timestamp($svDate, $svDateOutput)
{
$year = substr($svDate,0,4);
$month = substr($svDate,4,2);
$day = substr($svDate,6,2);
$hour = substr($svDate,8,2);
$minute= substr($svDate,10,2);
$sec = substr($svDate,12,2); $svDateOutput = ereg_replace ("YYYY", $year, $svDateOutput);
$svDateOutput = ereg_replace ("MM", $month, $svDateOutput);
$svDateOutput = ereg_replace ("DD", $day, $svDateOutput);
$svDateOutput = ereg_replace ("hh", $hour, $svDateOutput);
$svDateOutput = ereg_replace ("mm", $minute, $svDateOutput);
$svDateOutput = ereg_replace ("ss", $sec, $svDateOutput);
echo $svDateOutput;
};
call it like:
<? $date_output = 'MM-DD-YYYY'; func_change_timestamp($row['timestamp_field'], $date_output);?>
see the function ;)
if you want to your code to stay like it is now, change the 'echo $svDateOutput;' inside the function to 'return $svDateOutput;'
just use it like this:
<? $date_output = 'MM-DD-YYYY'; //dont know if 'MM-DD-YY' works
func_change_timestamp($row['timestamp_field'], $date_output);?>
function func_change_timestamp($svDate, $svDateOutput)
{
$year = substr($svDate,2,4);
$month = substr($svDate,4,2);
$day = substr($svDate,6,2);
$hour = substr($svDate,8,2);
$minute= substr($svDate,10,2);
$sec = substr($svDate,12,2);
$svDateOutput = ereg_replace ("YY", $year, $svDateOutput);
$svDateOutput = ereg_replace ("MM", $month, $svDateOutput);
$svDateOutput = ereg_replace ("DD", $day, $svDateOutput);
$svDateOutput = ereg_replace ("hh", $hour, $svDateOutput);
$svDateOutput = ereg_replace ("mm", $minute, $svDateOutput);
$svDateOutput = ereg_replace ("ss", $sec, $svDateOutput);
echo $svDateOutput;
};
next use:
<? $date_output = 'MM-DD-YY'; func_change_timestamp($row['timestamp_field'], $date_output);?>
function func_change_datetime($svDate, $svDateOutput)
{
$year = substr($svDate,0,4);
$month = substr($svDate,5,2);
$day = substr($svDate,8,2);
$hour = substr($svDate,11,2);
$minute= substr($svDate,14,2);
$sec = substr($svDate,17,2);
$svDateOutput = str_replace ("YYYY", $year, $svDateOutput);
$svDateOutput = str_replace ("MM", $month, $svDateOutput);
$svDateOutput = str_replace ("DD", $day, $svDateOutput);
$svDateOutput = str_replace ("hh", $hour, $svDateOutput);
$svDateOutput = str_replace ("mm", $minute, $svDateOutput);
$svDateOutput = str_replace ("ss", $sec, $svDateOutput);
echo $svDateOutput;
};
just look at the code. Its not like I dont wanne help, but getting al your questions anwswered isnt gonna help you much in the long run.
inside the functions are 2 php default fucntions:
substr() [nl3.php.net]
and
ereg_replace() [nl3.php.net]
take a look at what they actually do.
function func_change_timestamp($svDate, $svDateOutput)
$svDate is your date string (timestamp), $svDateoutput is the format we want it displayed in.
thats all you're gonna get from me this time ;)
its so easy, just take the time