• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

mysql to populating a textarea with for loop

hi im setting up a football team website, and when a result is added, i have the add match page displaying
a text area, that automatically lists every player in the team from the database.
but i cant get it to display appropriately.
i want the text area to display every player found in the database by the following attributes and on a new line
without it displaying a new line character. then the admin guy can just delete the players from the list who
werent involved in that particular game.

----------------------
$no $name $pos

i.e.

1     yoshi   GK
2     mario  DEF
3     luigi     Mf
4     Toad   FWD

----------------------

code
--------

<textarea name="mSheet" cols="30" rows="16"><?
     $query = "SELECT * FROM players ORDER BY pNo";
     $result = mysql_query($query, $db);
     $players = mysql_num_rows($result);

      for ($i=0; $i < $players; $i++) {
            $pNo = mysql_result($result, $i, "pNo");                                  //player squad number
            $pName = mysql_result($result, $i, "pName");                            //player name
            $pPosition = mysql_result($result, $i, "pPosition");                                  //player position
            
                                $display =        $pNo.' '.$pName.' '.$pPosition;
            echo $display;
                  
                      echo "<br";  <-- this is wrong, it displays <br. im unsure of how to start a new line without it showing
      } ?>                
</textarea>

help much appreciated thanks
0
koston
Asked:
koston
  • 4
  • 2
1 Solution
 
BogoJokerCommented:
The newline character is "\n"
It must be in double quotes for the new line to get sent.
\t is tab
\r is cariage return (can never spell that)

Joe P
0
 
kostonAuthor Commented:
super mate, i tried \n but i hadnt put it in double quotes, works fine now points awarded :)
0
 
BogoJokerCommented:
Great, enjoy =)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BogoJokerCommented:
I also experimented with padding techniques.
So a good trick would be something like this:

$str = "";
$count = 1;
foreach ($teamPlayers as $individual)
  $str .= "$count. $individual[name]\t$individual[position]\n";

The only problem with this is that a person's name might be Pecoraro and another person's name might be Le.  The tabs would not exactly even up.  There is a php function called str_pad() and I played around with it so something like:

foreach ($teamPlayers as $individual)
  $str .= "$count. " . str_pad($individual[name], 10, ' ') . "\t$individual[position]\n";

That fixed most of my problems if not all.  Then the information in the textbox would line up nicely.  of course all the information I provided was completely made up, but I hope I passed the point on.

Joe P
0
 
kostonAuthor Commented:
hey cheerz mate i might have a go at implementing this especially when displaying it on the match report for example.
im in consideration on how automated to make the whole site. i was just going to make it so you add the goal scorers into a text box and thats it, ud have to add the goal tallys manually to each player profile.

or i was thinking that the team sheet textarea, you could just add say 1 at the end of that players row if that player scored 1 goal or 2 or whatever. then explode the row and get the goal value and auto increment the player profile goal tally.

this will add other problems tho like i have a update result page, so id have to store the players previous goal tally and increment/deincrement the tally by what ever the changed value was if it was changed. not sure how far im gonna go into this heh
0
 
BogoJokerCommented:
If you have a database it would be much easier then textfiles, so your on the right track. =)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now