View Single Post
Old 09-04-2012, 01:01 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,178
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
First of all, this makes no sense:
Code:
	$rows['date'] = date( "d/m/Y", $rows['date_ts'] );
        ...
     <td nowrap><? echo $rows['datefield']; ?></td>
You create a new element in the array--"date"--but then never use it. Instead, you use something called "datefield"??? What is going on?

*********

Another way to do this, though, would be to enhance your SQL query. And in the process get rid of the need to convert the date in PHP.

You don't bother to show that to us, but just as an example (and guessing about your date vs. datefield funniness):
Code:
SELECT DATE_FORMAT(date_ts,'%d/%m/%Y') AS datefield,
       datefield, shift, reason, person_covering, cost,
       IF ( staff_approved LIKE 'yes%', 'yes', 'no' ) AS doEdit
FROM yourtable
WHERE ...
My "doEdit" may be backwards. If so, just swap the 2nd and 3rd arguments of the if.

Then, in the PHP code:
Code:
<?php
while($rows=mysql_fetch_array($result))
{
?>
    <tr>
        <td nowrap><?php echo $rows['datefield']; ?></td>
        <td nowrap><?php echo $rows['shift']; ?></td>
        <td nowrap> <?php echo $rows['reason'];?></td>
        <td nowrap> <?php echo $rows['person_covering']; ?></td>
        <td nowrap> &pound;<?php echo $rows['cost']; ?></td>
        <td nowrap><?php if($rows['doEdit'] == 'yes')
        {
            ?>
            <a href="updaterecord.php?id=<?php echo $rows['id'];?>">Edit</a>
            <?php
        }
        ?>
        </td>
    </tr>
<?php
}
?>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
jake66 (09-05-2012)