php resource 使用,PHP resource id #4

问题

I'm still a novice with php and mysql. I've spent the last several days trying to figure this out and searching the net for answers, but just can't get this stupid thing working... I have a gaming site (http://houston-by-night.com), people log on, input their character sheet, and are supposed to be able to pull up the sheet again later. Now, the code was working fine, pulled up the page like it is supposed to, then suddenly on 4/29/15, it stopped working and starting giving me the "Resource id #4".

So.. here's the code:

$sql="SELECT * FROM topdata a, venuetop b, stats c, mid_data d, influence e, botdata f, accounts g WHERE (a.char_name=b.char_name) AND (b.char_name=c.char_name) AND (c.char_name=d.char_name) AND (d.char_name=e.char_name) AND (e.char_name=f.char_name) AND (f.char_name=g.log_name) AND (a.char_name=\"$_POST[char_name]\")";

$result=mysql_query($sql)

or die ("Couldn't get character data.
".mysql_error()."
Please contact Savvannis with your login name, character name, the above error and the page address above.");

$row = mysql_fetch_array($result);

echo $sql;

echo $result;

and the results on the webpage:

SELECT * FROM topdata a, venuetop b, stats c, mid_data d, influence e, botdata f, accounts g WHERE (a.char_name=b.char_name) AND (b.char_name=c.char_name) AND (c.char_name=d.char_name) AND (d.char_name=e.char_name) AND (e.char_name=f.char_name) AND (f.char_name=g.log_name) AND (a.char_name="Monroe")Resource id #4

And the character sheet is blank... the char_name is correct for the sheet chosen, the html portion is there, but nothing else.

Does anyone have any ideas on what changes I can try to get the information to pull up and populate the page as it's supposed to??

回答1:

You're getting resource id #4 because your query result is a resource. You need to extract the results/data from it.

You're trying to echo out $result which won't ever hold the values fetched from the database, it'll only ever have the result of the query, either being the query object or a Boolean.

What you want to do is look at your $row variable:

print_r($row);

来源:https://stackoverflow.com/questions/30586471/php-resource-id-4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值