PDA

View Full Version : Help Convert to a function


owner
09-15-2007, 08:11 PM
Hello

I am trying to learn functions and if someone could convert this to a function I could learn off of this, then I could learn how to convert my other code to functions.

<?php
do {
print '<div class="boxtop"><h4 style="margin: 0px; font-size: 10px;">';
echo $row['news_title'];
print '</h4></div>';
print '<div class="boxbottom"><br /><b>';
echo $lang_id, $row['news_id'].'<br />';
echo $lang_author, $row['news_author'].'<br />';
echo $lang_date, $row['news_date'].'</b><br /><br />';
echo $row['news_body'].'</div>';
} while ($row = mysql_fetch_array($result));
?>


That is what I have displaying my news. I don't know anything about functions yet, so if you do choose to help, could you please comment the code so I can learn and see what you are doing.

Thank you soooooo much!
-Owner

davidj
09-15-2007, 08:38 PM
this doesnt lend its self to a function really. You could do it but will be more complicated when debugging

stick it in an include and bobs your uncle

also you have mixed print and echos....?

its better to do it like this..


<?php do { ?>
<div class="boxtop"><h4>;
<?php echo $row['news_title']; ?>
</h4></div>;
<div class="boxbottom"><br />;
<?php echo $lang_id . ",". $row['news_id']; ?><br />;
<?php echo $lang_author . ",". $row['news_author']; ?><br />;
<?php echo $lang_date. ",". $row['news_date']; ?><br />;
<?php echo $row['news_body'] ?></div>;

<?php } while ($row = mysql_fetch_array($result)); ?>


also remember to style your code using CSS