Populate Text Area from Query not working? Help...

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
ridshack
Forum Commoner
Posts: 29
Joined: Wed Oct 11, 2006 10:34 pm

Populate Text Area from Query not working? Help...

Post by ridshack »

Im having trouble getting a query to populate a text area.... The results I get is the query and then the textarea with nothing in it. Any ideas what I should try?

Code: Select all

<TEXTAREA NAME='Body' rows='30' cols='85'>
<?php while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "Ticket# :{$row['id']} <br>" .
        "Subject : {$row['Subject']} <br>" .
"Client : {$row['Queue']} <br>" .
"LastUpdatedBy : {$row['LastUpdatedBy']} <br>" .

         "Status : {$row['Status']} <br><br>";

}
 ?>
 </textarea>
Thank you,
Ridshack
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

You could use mysql_fetch_assoc but that isn't the source of your problem. You haven't included your mysql_query declaration as the SQL could be failing. You may want to temporarily show the number of rows using mysql_num_rows.
ridshack
Forum Commoner
Posts: 29
Joined: Wed Oct 11, 2006 10:34 pm

Post by ridshack »

Oh, My queries work. They just don’t get put in the text area. They get put before the text area. I don’t understand how your suggestion would help. I haven’t been doing this for very long.


Thank you,
Rid
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could you post us a little of the generated HTML?

Mac
choppsta
Forum Contributor
Posts: 114
Joined: Thu Jul 03, 2003 11:11 am

Post by choppsta »

Whenever you want to output something to HTML you should htmlspecialchars() it first. This will stop any HTML in your output from breaking the display.

Also, in a textarea you shouldn't use <br>s, use a new line character "\n" for line breaks.

Code: Select all

<?php 
while ($row = mysql_fetch_assoc($result))
{
	foreach ($row as $k => $v) { $row[$k] = htmlspecialchars($v);}
	echo 'Ticket# :'.$row['id']."\n".'Subject : '.$row['Subject']."\n".'Client : '.$row['Queue']."\n".'LastUpdatedBy : '.$row['LastUpdatedBy']."\n".'Status : '.$row['Status']."\n\n";
}
 ?> 
Oh, and one more thing, in the spirit of all things XHTML you should be consistent with your HTML:

Code: Select all

<textarea name="Body" rows="30" cols="85"></textarea>
Post Reply