PHP에서 나는 사용자가 마지막으로 로그인 한 이후에 대화방 내에 게시 된 메시지 수를 찾기 위해 데이터베이스를 쿼리하는 코드 라인을 가지고 있습니다. data.messages 내부의 하위 문자열 (사용자 "닉네임")을 찾습니다. 누군가가 제대로php 쿼리에서 strpos의 올바른 구문
, 즉 당신의 $의 ROW2에 = 줄 당신이 PHP 함수 strpos를 사용하고 그것은 나에게 보이는
$row2 = mysql_fetch_array(mysql_query("SELECT count(d.msgid) as con2,d.msgid FROM `data` as d where d.room= '".$row['room']."' and d.msgid>(select u.lastmsgnotified from user as u where u.id='".$row['id']."') and strpos(d.message,$row[nickname])!==false order by d.msgid desc limit 0,1"));
if(intval($row2['con2'])>1){
sendGCM($row2['con2']." New Alerts in ".$row['room'],$row['deviceid']);
}else if(intval($row2['con2'])>0){
$rok = mysql_fetch_array(mysql_query("select u.*,m.* from user as u, `data` as m where u.id=m.userid and m.msgid=".$row2['msgid']));
if($rok['nickname']=='')
$rok['nickname'] = 'A User';
sendGCM($rok['nickname']." Has Alerted you in room '".$rok['room']."'",$row['deviceid']);
}
불쾌한 코드를 : 당신은 그들 중 하나를 사용하는 것을 선호 거라고 경우도보고 다른 MySQL의 문자열 함수의 목록을 확인할 수 있습니다. 그런 식으로 체인 데이터베이스 호출을 절대로하지 마십시오. 당신은 아무 것도 실패 할 수 없다고 단순히 가정하고 있습니다. 그런 연쇄 반응은 실패를 더 큰 문제로 단순하게 혼합 할 것입니다. –
이 쿼리를 수행하는 더 좋은 방법의 예가 있습니까? strpos() – TWeeKeD
'$ res = mysql_query ($ sql) or die (mysql_error());에 대한 내 구문 질문에 대한 답을 알고 계신가요? $ row = mysql_fetch_assoc ($ res);'. strpos에 관해서는 http://php.net/strpos –