Home >Backend Development >PHP Tutorial > mysql 来帮忙解决一个有关问题,多谢

mysql 来帮忙解决一个有关问题,多谢

WBOY
WBOYOriginal
2016-06-13 13:53:26712browse

mysql 高手进来帮忙解决一个问题,谢谢
//连接数据库
$db=mysql_connect($db_host,$db_user,$db_passwd) or die('Can not connect to database');
mysql_select_db($db_name) or die('No database');

$q31="select * from member where sh1='$arr[sh1]' and status='0' order by id Limit 0,10";
$r31=mysql_query($q31,$db);
while ($a31=mysql_fetch_array($r31))
{
$id.="$a31[id]";
}

//上面输出的10条数据中,我要进一步比对10个数据的IP是否包含ID为:“1005”的ID,请问如果写?我下面这样写不对啊:
$data=“1005”;
foreach ($id as $data)
{
echo "包含";
}else{
echo "不包含";
}
//请高手帮忙写出最高效的代码,谢谢!


------解决方案--------------------
上面写了

/如果是要取得数据之后再判断
$Myid=array();
while ( $a31 = mysql_fetch_array ( $r31 ) ) {
$id = $a31['id'];
$Myid[]=$id;
}

foreach ($Myid as $Idvalue){
if ($Idvalue==1005){
echo 'id列表包含1005';
break;
}
}


以后问问题最好说清楚些, 是否有 等于 1005 的id 或者早点说清楚$a31[id]数组是否包含1005

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