请教php关于mysql_fetch_array()的问题

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in d:\usr\www\html\app\member\include\config.inc.php on line 12

程序:

<?php
$dbhost = "localhost"; // 数据库主机名
$dbuser = "root"; // 数据库用户名
$dbpass = ""; // 数据库密码
$dbname = "buy5000"; // 数据库名

mysql_connect($dbhost,$dbuser,$dbpass) or die ('');
$sql = "select * from web_system";
$result = mysql_db_query($dbname,$sql);
$row = mysql_fetch_array($result);
$website=$row['website'];
$msg_member=$row['msg_member'];
$msg_member_tw=$row['msg_member_tw'];
$msg_member_en=$row['msg_member_en'];
$define_data='lovemyself';
$flaqa=$row['flaq'];
$msg_login_tw=$row['msg_login_tw'];
$msg_login=$row['msg_login'];
$site="/tpl";
?>
选择联盟:
Notice: Undefined index: lx_select in d:\football\huangguan\member\lx_select_show.php on line 2

Notice: Undefined index: page_no in d:\football\huangguan\member\lx_select_show.php on line 3

程序:<?
$lx_select=$_GET['lx_select'];
$s_page=$_GET['page_no'];
if($s_page=="")
{$s_page=0;}
$page_size =40;

对于后来补充这个问题,我用内嵌函数前边加@的方法解决了,这样就不会显示错误了,但是能正常工作吗?
最新回答
浪徒

2024-10-23 08:57:53

mysql_db_query()
改成
mysql_query()
__________________________
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
...
}
你连while 循环都不知道还写什么PHP?
人家是省略了输出语句
你的原方法只能得到一行结果
用循环可以将所有符合条件的结果都循环赋给$row
_________________________________________
Undefined index:是指你的代码里存在:“变量还未定义、赋值就使用”的错误,
这个不是致命错误,不会让你的php代码运行强行中止,但是有潜在的出问题的危险
暴力萌萌

2024-10-23 08:17:48

$result = mysql_db_query($dbname,$sql);
$row = mysql_fetch_array($result);

建议换成

!mysql_select_db($dbname) && die("select db error...");
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
...
}
梦的河流

2024-10-23 08:46:38

mysql_connect($dbhost,$dbuser,$dbpass) or die ('');
$sql = "select * from web_system";
$result = mysql_db_query($dbname,$sql);

建议改为

$link_id = mysql_connect($dbhost,$dbuser,$dbpass) or die ('');
Mysql_Select_DB($dbname,$link_id)
$sql = "select * from web_system";
$result = mysql_query($sql);

还有,你返回的数据$row是一个二维数组吧??