格式化从数据库访问的数据

时间:2013-08-25 15:53:11

标签: php javascript

我是网页设计的新手。我使用PHP从MySQL数据库访问数据。数据显示为列表或与表格相同,我需要知道如何格式化数据以填充我的网页中的文本字段。

是由JavaScript完成的吗?

使用代码:

<html>
<head>
<title>Retrieve data from database </title>
</head>
<body>

<?php
// Connect to database server
mysql_connect("mysql.myhost.com", "user", "sesame") or die (mysql_error ());

// Select database
mysql_select_db("mydatabase") or die(mysql_error());

// SQL query
$strSQL = "SELECT * FROM people";

// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);

// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {

   // Write the value of the column FirstName (which is now in the array $row)
  echo $row['FirstName'] . "<br />";

  }

// Close the database connection
mysql_close();
?>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

我不确定你到底想要什么,但我认为你的意思是把它放在......

echo "<input type=\"text\" name=\"Firstname[]\" value=\"".$row['FirstName']."\" >";}