mysql to populating a textarea with for loop

Posted on 2006-04-25
Last Modified: 2012-08-13
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


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



<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
      } ?>                

help much appreciated thanks
Question by:koston
    LVL 17

    Accepted Solution

    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

    Author Comment

    super mate, i tried \n but i hadnt put it in double quotes, works fine now points awarded :)
    LVL 17

    Expert Comment

    Great, enjoy =)
    LVL 17

    Expert Comment

    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

    Author Comment

    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
    LVL 17

    Expert Comment

    If you have a database it would be much easier then textfiles, so your on the right track. =)

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now