Question about print_output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dawho9
Forum Newbie
Posts: 4
Joined: Mon Jun 17, 2002 5:55 pm

Question about print_output

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
dawho9
Forum Newbie
Posts: 4
Joined: Mon Jun 17, 2002 5:55 pm

Post 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
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post 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).
Post Reply