DeMolen
05-26-2008, 10:56 AM
Dear php coders,
I'd be very grateful for any help with the following problem. I'm setting up a page which calls in data from a linked mySQL database. If a certain field is empty (in this case 'duration'), it shouldn't print anything, if the field has content it should print the content plus an apostrophe and then continue to list the rest of the data for each record.
This is my faulty script - I'd be pleased if anyone can correct it for me. I'm still a beginner with php, as may be obvious if I'm making a silly mistake here.
It's the 6 lines starting if(trim ... that I'm not sure about, the rest works ok.
Many thanks in advance for any assistance.
<?
while( $row=mysql_fetch_assoc($recordset)) {
print '<tr><td valign="top" width="150"><b>'. $row['title'] .'</b></td><td colspan="2" valign="top">'. $row['subtitle'] .'</td><td></td></tr>
<tr><td></td><td valign="top"> <i>'. $row['date'] .' ';
if (trim($duration)=='') {
print '';
}
else {
print $row['duration'] .'’ ';
}
print $row['format'] .' '. $row['recording'] .'</td><td align="right" valign="top"><i>'. $row['instrumentation'] .'</i> <td align="right" valign="bottom">£'. $row['price'] .'</td></tr>';
}
?>
I'd be very grateful for any help with the following problem. I'm setting up a page which calls in data from a linked mySQL database. If a certain field is empty (in this case 'duration'), it shouldn't print anything, if the field has content it should print the content plus an apostrophe and then continue to list the rest of the data for each record.
This is my faulty script - I'd be pleased if anyone can correct it for me. I'm still a beginner with php, as may be obvious if I'm making a silly mistake here.
It's the 6 lines starting if(trim ... that I'm not sure about, the rest works ok.
Many thanks in advance for any assistance.
<?
while( $row=mysql_fetch_assoc($recordset)) {
print '<tr><td valign="top" width="150"><b>'. $row['title'] .'</b></td><td colspan="2" valign="top">'. $row['subtitle'] .'</td><td></td></tr>
<tr><td></td><td valign="top"> <i>'. $row['date'] .' ';
if (trim($duration)=='') {
print '';
}
else {
print $row['duration'] .'’ ';
}
print $row['format'] .' '. $row['recording'] .'</td><td align="right" valign="top"><i>'. $row['instrumentation'] .'</i> <td align="right" valign="bottom">£'. $row['price'] .'</td></tr>';
}
?>