[code={php}]
<?php
include("conn.php");
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?
$sql = "SELECT * FROM message ORDER BY id ASC ";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?=$row[content]?></td>
</tr>
<?
}
?>
</table>
[/code]
我的conn.php文件没问题
可是为什么不显示输出结果
<?php
include("conn.php");
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?
$sql = "SELECT * FROM message ORDER BY id ASC ";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?=$row[content]?></td>
</tr>
<?
}
?>
</table>
[/code]
我的conn.php文件没问题
可是为什么不显示输出结果
<?
$sql = "SELECT * FROM message ORDER BY id ASC ";
echo $sql;
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?=$row[content]?></td>
</tr>
<?
}
?>
</table>
这是打开网页后的源文件
<?php
phpinfo();
?>
看看能不能运行,首先要服务器能解析php,然后才会有short_open_tag的设置,如果你服务器都没有设置好处理php所有php.ini设置没意义
10楼的,我试了还是显示不了
已经激活了
但是就是读取不了短标记
<?php echo $row["xxx"];?>
但是我用phpinfo()函数显示时
short_open_tag=off,
现在我该怎么设置才能把短标记激活
但是代码又出现错误了
[code={php}]
<?php
include("conn.php");
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?
$sql = "SELECT * FROM message ORDER BY id ASC ";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?=$row[content]?></td>
</tr>
<?
}
?>
</table>
[/code]
运行后报的错误
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\BBS\list.php on line 7Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\BBS\list.php on line 7Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\BBS\list.php on line 8
在另外一个页面里面就正常的可以引用
我是刚学的,看的视频上面用这个
我就用这个
如果是,conn.php文件内容?
conn.php文件单独的页面
<?php
function db_connect()
{
$db = @ new mysqli("127.0.0.1","root","","bbs");
if (mysqli_connect_errno())
{
echo "数据库连接失败";
echo mysqli_connect_error();
exit;
}
return $db;
}
?>
我现在把这个页面改成
<?php
include("conn.php");
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?
$db = db_connect();
$sql = "SELECT * FROM message ORDER BY id ASC ";
$rs =$db->query($sql);
while($row=mysql_fetch_array($rs))
{
?>
<tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?=$row[content]?></td>
</tr>
<?
}
?>
</table>
报的错误是
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\BBS\list.php on line 9
我的问题解决了
while($row=mysql_fetch_array($rs)) 这个地方也要用mysqli的mysqli_fetch_array