Home >Backend Development >PHP Tutorial > 请问一个查询数据库输出后进行判断的有关问题

请问一个查询数据库输出后进行判断的有关问题

WBOY
WBOYOriginal
2016-06-13 12:59:37989browse

请教一个查询数据库输出后进行判断的问题!

<br />
<?php<br />
<br />
$mysql_server_name='localhost';<br />
$mysql_username='root';<br />
$mysql_password='123456';<br />
$mysql_database='you';<br />
<br />
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);<br />
<br />
mysql_select_db($mysql_database,$conn);<br />
<br />
mysql_query("set names 'utf8'");<br />
<br />
$sql = "SELECT * FROM `member` WHERE username LIKE 'xiha'";<br />
<br />
$result = mysql_query($sql,$conn);<br />
<br />
$row = mysql_fetch_array($result);<br />
<br />
mysql_close($conn); <br />
<br />
if($row['groupid'] = '1'){<br />
        $capacity = '100';<br />
} else if($row['groupid'] = '10'){<br />
        $capacity = '1000';<br />
} else {<br />
        exit();<br />
}<br />
<br />
echo $capacity;<br />
<br />
?><br />


数据库格式为:

uid   username     groupid
1     haha         1
2     xiha         10

用if   elseif 判断时:
输出的$capacity 始终是第一次的判断的值 100
if($row['groupid'] = '1'){
        $capacity = '100';
}


------解决方案--------------------
if($row['groupid'] == '1'){

一个 = 是赋值
两个才是比较

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn