php如何打开mysql表并将数据显示在网页上?

我本地用 我的MYSQL数据库中有一些数据 我想把他们在一个网页上显示出来
数据库名 root 密码 19871114 表 message
表内有 title(主题)content(内容)
请大家帮我写个代码 让他在一个页面把所有数据分主题和类容罗列出来
我只是本地使用 不用考虑任何其他因数
一楼的可以运行 但是不能显示中文郁闷啊

<?php
if (@mysql_connect('127.0.0.1','root','19871114')){
$sql='select title,content from 数据库.message';
$res=mysql_query($sql);
if ($res){
echo "<table border=1><tr><th>标题<th>内容";
while ($row=mysql_fetch_array($res))
echo "<tr><td>$row[title]<td>$row[content]";
echo '</table>';
mysql_free_result($res);
}else echo "执行SQL $SQL 错误,错误信息:".mysql_error();
}else echo "数据库连接失败,错误信息:".mysql_error();
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-10-22
mysql_connect("localhost", "root", "19871114");
mysql_select_db(你得数据库名);
$sql="select * from message"
$result=mysql_query($sql);
while($output=mysql_fetch_array($result))
{
echo $output["title"];
echo $output["content"];
}
mysql_free_result($result);
第2个回答  2008-10-22


PHP调用MYSQL的类
$shop = new Db_Mysql("localhost","root","19871114","message");
$shop->select("*","title");
while ( $test=mysql_fetch_array($shop->result) )
{
echo $test['content']."<br>";
}
第3个回答  2020-05-24
<?php
if
(@mysql_connect('127.0.0.1','root','19871114')){
$sql='select
title,content
from
数据库.message';
$res=mysql_query($sql);
if
($res){
echo
"<table
border=1><tr><th>标题<th>内容";
while
($row=mysql_fetch_array($res))
echo
"<tr><td>$row[title]<td>$row[content]";
echo
'</table>';
mysql_free_result($res);
}else
echo
"执行SQL
$SQL
错误,错误信息:".mysql_error();
}else
echo
"数据库连接失败,错误信息:".mysql_error();
?>
第4个回答  2019-10-02
<?php
if
(@mysql_connect('127.0.0.1','root','19871114')){
$sql='select
title,content
from
数据库.message';
$res=mysql_query($sql);
if
($res){
echo
"<table
border=1><tr><th>标题<th>内容";
while
($row=mysql_fetch_array($res))
echo
"<tr><td>$row[title]<td>$row[content]";
echo
'</table>';
mysql_free_result($res);
}else
echo
"执行SQL
$SQL
错误,错误信息:".mysql_error();
}else
echo
"数据库连接失败,错误信息:".mysql_error();
?>

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网