Have an account? Sign in
Login  Register  Facebook
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?
Started: September 21, 2011 Latest Activity: September 21, 2011 php

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

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
In: September 21, 2011

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 system
while($row =mysql_fetch_array($result))
{    
$html[] =\"{the name is[\"\".$row[\"name\"].\"\"]}\";
}
and
file_put_contents(\"new.html\",implode(\"\\n\",$html));

Posted: MacOS
In: September 21, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer