|
PHP generate html with mysql query.
Good night friends:
I have a new question in PHP generate html with mysql query.
<?
require_once("database.php");
mysql_query("SET NAMES 'utf8'");
$result=mysql_query("SELECT* FROM table");
while($row =mysql_fetch_array($result))
{
$html ="{the name is[\"".$row["name"]."\"]}";
echo $row['name'];
}
file_put_contents("new.html", $html);
?>
I can get all the query result as a row with echo. But when I open the generated new.html, I only see the last one name from my mysql table. What was it caused?
2 Answers
use this if you want to use <ul>
$html ="<ul>";
while($row =mysql_fetch_array($result))
{
$html .="<li>{the name is["".$row["name"].""]}</li>";
}
$html .="</ul>";
Posted: Go 0 of 0 people found this answer helpful. Did you? Yes No
because of you will get the last $html, you can do it like that:
$html = \'\';
while($row =mysql_fetch_array($result))
{
$html .=\"{the name is[\"\".$row[\"name\"].\"\"]}\";
}
the dot [.] will do that job
or with the array systemwhile($row =mysql_fetch_array($result))
{
$html[] =\"{the name is[\"\".$row[\"name\"].\"\"]}\";
}andfile_put_contents(\"new.html\",implode(\"\\n\",$html)); Posted: MacOS 1 of 1 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved


Thanks for a quick reply.But if I add a ul in the code. how to do it?
September 21, 2011