Jump to content

[SOLVED] Printing into a textarea


emilg

Recommended Posts

Hello everyone!

I'm quite new to php, so forgive me if this is really simple, but I just can't figure it out.

 

I have two functions that print a certain row with some variables. What I want to do is to print these lines(from both functions) into a single textarea , which will be hidden unless a user selects to view it. I understand hiding the textarea shouldn't be too hard, but I have no idea of how can I print into that textarea from both functions.

 

Any help would be greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/164293-solved-printing-into-a-textarea/
Share on other sites

Thanks for your fast reply.

 

One of my functions does the following:

function mobHit()
{
  global $char_info;
  global $mon_stats;
  global $user_check;
  global $mon_dmg;
  $query = "call monHit('$mon_dmg', '$user_check')";
  $result = mysql_query($query);
  $char_info['health'] = $char_info['health'] - $mon_dmg;
  ?><font color="red"><?
  print ($mon_stats['name']. " hits you for ".$mon_dmg."<br>");
  }

 

The second function does something similar and has the same print line.

 

Both functions are ran from a while loop. As it works now, they just print the line into the page.

What I want to do is to print everything into a textarea instead, so I can hide and show it whenever I want to.

In general, functions should return the results produced by the function, rather than printing the results inside of the function. Once you do this, your function can be used in any situation.

 

You could for example assign or concatenate the results returned by the function into a variable that you then print in a textarea.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.