Page 1 of 1

Question about print_output

Posted: Mon Jul 08, 2002 9:01 pm
by dawho9
I hope this is a simple question. I was using a php script someone had written and posted in the docs on how to replace code (can be found here: http://www.phpbuilder.com/columns/ying20000718.php3)

I am pulling the information from a MySQL database. On one page it works great, because I am pulling a single record and using the command like:

Code: Select all

<?php print_output($myrow2&#1111;"subject"]) ?>


However, in another section, I am pulling multiply rows by using the fetch command. Below is the code:

Code: Select all

($myrow2 = mysql_fetch_array($result2)) &#123; 
printf(" 
<fieldset> 
<legend class='fieldset'>%s</legend> 
%s</fieldset> 
<p>\n" 
, $myrow2&#1111;"subject"], $myrow2&#1111;"message"] 
); 
&#125;?>
However, I do not know how call upon my print_output command. I'm fairly new at this, so thanks in advance.

Richard

Posted: Tue Jul 09, 2002 7:19 am
by twigletmac
Try something like:

Code: Select all

<?php
while ($myrow2 = mysql_fetch_assoc($result2)) &#123; 
    echo '<fieldset>';
    echo '<legend class="fieldset">'.print_output($myrow&#1111;'subject']).'</legend>';
    echo print_output($myrow2&#1111;'message']).'</fieldset>';
&#125;
?>
Mac

Posted: Tue Jul 09, 2002 4:49 pm
by dawho9
Perfect.

Just a code question, as I am trying to learn as I go, not just copy other peoples work. In the line:

echo print_output(variable).'normal code.;

I am assuming that I can use this type of code anywhere I used the %s before, and as long as I use a '.' this allows me to specify a variable.

So I guess the question is, is there any disadvantage of doing it this way, as opposed to using the %s. This is much easier to read for myself,

Just wondering,

Richard

Posted: Tue Jul 09, 2002 6:01 pm
by llimllib
no, there's no disadvantage. In fact, people use too much printf and sprintf where it's not necessary in PHP, so that's discouraged. Using the '.' operator is usually easier and clearer (IMHO).