if(!$result) 혹은 if(isset($result)) 결과값 Null 표시 > 기술자료

본문 바로가기

사이트 내 전체검색

if(!$result) 혹은 if(isset($result)) 결과값 Null 표시 > 기술자료

PHP if(!$result) 혹은 if(isset($result)) 결과값 Null 표시

페이지 정보


본문

<?php
$query = "select * from 테이블이름 order by 조건절 desc";
$result = mysql_query($query);
echo $result;    //<<--- 출력해보면 Resource id #2 가 나옵니다.
if(!$result) {    //<<----- 이것이 기능을 다 하지 못함..
  echo "등록된 내용이 없습니다!\n";   //<<--- 메세지!
}
else {
  while($row = mysql_fetch_array($result)) {
    echo $row[name];
  }
}
?>



isset  -  변수가 설정되지 않은 경우 NULL   /   Determine if a variable is set and is not NULL
PHP버전이 올라가면서  !  대신에 변수값이 있나 없나를 확인하는  isset  함수를 사용
<?php
$query = "select * from 테이블이름 order by 조건절 desc";
$result = mysql_query($query);
$data = mysql_fetch_array($result);
$isset_check = $data["mb_id"];  // 필드 데이타 하나를 호출합니다.
//echo $isset_check;  // 정상보이는지 확인

if(isset($isset_check)) { // 자료 있을때
  while($row = mysql_fetch_array($result)) {
    echo $row[name];
  }
} else { // 자료 없을때
  echo "등록된 내용이 없습니다!\n";   //<<--- 메세지!
}



5.4.0 이후 : 문자열이 아닌 숫자 오프셋을 선택하면 이제 반환값이 FALSE 로 변경
PHP 5.4 changes how isset() behaves when passed string offsets.
<?php
$expected_array_got_string = 'somestring';
var_dump(isset($expected_array_got_string['some_key']));
var_dump(isset($expected_array_got_string[0]));
var_dump(isset($expected_array_got_string['0']));
var_dump(isset($expected_array_got_string[0.5]));
var_dump(isset($expected_array_got_string['0.5']));
var_dump(isset($expected_array_got_string['0 Mostel']));
?>
Output of the above example in PHP 5.3 -> 5.4:
    5.3      -->       5.4
bool(true)  -->  bool(false)
bool(true)  -->  bool(true)
bool(true)  -->  bool(true)
bool(true)  -->  bool(true)
bool(true)  -->  bool(false)
bool(true)  -->  bool(false)



관련자료
http://phpschool.com/link/qna_db/47130 
http://www.phpschool.com/link/qna_html/34626 
http://www.php.net/manual/en/function.isset.php

댓글목록

등록된 댓글이 없습니다.


Total 78건 3 페이지
  • RSS
기술자료 목록
38
Adobe   52952  2013-03-18 09:29  
37
Adobe   28830  2012-12-23 17:10  
36
Adobe   18446  2012-12-21 19:32  
35
Adobe   12898  2012-04-22 15:43  
34
Adobe   21132  2012-03-16 17:16  
33
Adobe   16120  2011-11-16 23:15  
32
Adobe   16343  2011-11-04 10:23  
31
Adobe   20307  2011-10-31 20:14 ~ 2011-11-01 00:00  
30
Adobe   16614  2011-09-29 23:48  
29
Adobe   23593  2011-03-27 22:09  
28
Adobe   24887  2010-11-09 14:58  
27
Adobe   25030  2010-10-06 00:38  
26
Adobe   14603  2010-08-07 11:39  
25
Adobe   48419  2010-05-02 13:05  
24
Adobe   60934  2009-12-09 19:30 ~ 2013-04-09 00:00  
23
Adobe   20871  2009-10-29 10:11  
22
Adobe   25248  2009-10-07 14:51  
21
Adobe   53193  2009-08-20 14:16  
20
Adobe   14890  2009-04-28 11:39  
19
Adobe   13326  2009-04-25 18:18  

검색

해피정닷컴 정보

회사소개 회사연혁 협력사 오시는길 서비스 이용약관 개인정보 처리방침

회사명: 해피정닷컴   대표: 정창용   전화: 070-7600-3500   팩스: 042-670-8272
주소: (34368) 대전시 대덕구 대화로 160 대전산업용재유통단지 1동 222호
개인정보보호책임자: 정창용   사업자번호: 119-05-36414
통신판매업신고: 제2024-대전대덕-0405호 [사업자등록확인]  
Copyright 2001~2026 해피정닷컴. All Rights Reserved.