28 users online (1 members and 27 guests)  


  Results 1 to 2 of 2

Related

  1. Replies: 6
  2. Replies: 2
  3. How to Decode the data from Database using database handler?    Forum: Search Engine Optimization - SEO - Forum
    Replies: 1
  4. Replies: 4
  1. #1
    Ariel's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2002
    Posts
    5

    Question Is it possible to dynamically populate a textarea with data from a database?

    Hello,

    I'm trying to re-create a listbox with the textarea element. Is it possible to dynamically populate the textarea with data from a database?. I want the data to list vertically like a listbox.

    If this possible, can you please provide an example of how I can go about doing this?.

    Thanks,
    Ariel

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Sure. Heres an example -

    PHP Code:
    $result mysql_query("SELECT * FROM league_news ORDER BY ident DESC",$db);
        
        
        
    printf("<form method=\"post\" action=\"news_handler.php\">\n");
        
    printf("<select name=\"todelete\">\n");
        
        
        
        
        while (
    $myrow mysql_fetch_row($result)) {
        
        
        
            
        
        
        
        
    printf("<option value=\"%s\"> \n"$myrow[5]);
        
    printf("%s\n"$myrow[0]);
        
    printf("</option>\n");
        
        
        
        
        
        }
        
        print(
    "<input type=\"submit\" value=\"delete\" style=\"padding: 0px; font: 9pt verdana, sans-serif;\">");
        
    printf("</form>");
        
        
    ?> 
    Edit: Oops. That how to fill a select, not a textarea, sorry.

    But the principal is the same. Write the textarea, then a loop from the database echo'ing or printing out what you need. Make sure you put a \n or \r\n character at the end of each to keep them separate.
    Last edited by QuietDean; 11-26-2002 at 02:35 PM.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?