Assigning a holw bunch of codes to a variable

 Question:

  Hi

I am retreiving data from the database (put inside a text area)


Code:


print"<textarea name=\"body\" id=\"body\" rows=\"5\" cols=\"10\">

$con=mysql_connect("localhost", "name", "password");
mysql_select_db("database",$con);

$qt = "SELECT * FROM friends ORDER BY Date DESC, Time DESC LIMIT 20;";

$rest = @mysql_query($qt,$con);

while($rt = @mysql_fetch_array($rest)){

many results

}

</textarea>";



The results are many and different
but they are all inside the text area

Is there a way i can create a variable which equals all these results

Like

$Results= Everything inside the text area




 Answers:
 
Try this :


Code:
<?

$con=mysql_connect("localhost", "name", "password");
mysql_select_db("database",$con);

$qt = "SELECT * FROM friends ORDER BY Date DESC, Time DESC LIMIT 20;";

$rest = @mysql_query($qt,$con);

$Results="";
while($rt = @mysql_fetch_array($rest)){
 
     // append the values to variable
    $Results.=$rt[field];

}

echo "<textarea name=\"body\" id=\"body\" rows=\"5\" cols=\"10\">$Results</textarea>";
?>



Commentaires

Posts les plus consultés de ce blog

XAJAX with PHP – The future of web development

XAJAX with PHP – The future of web development

Database connection pooling in ADO.Net