Page 1 of 1

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

Posted: Tue Oct 24, 2006 1:12 am
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

Posted: Tue Oct 24, 2006 2:39 am
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.

Posted: Tue Oct 24, 2006 3:12 pm
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

Posted: Wed Oct 25, 2006 3:53 am
by twigletmac
Could you post us a little of the generated HTML?

Mac

Posted: Wed Oct 25, 2006 5:36 am
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>