Header

  1. View current page

    kkamagui의 프로그래밍 작업실

Profile_image?t=1221830958&type=big
온갖 자료가 난무하는 kkamagui의 Springnote~!!!
166

04 PHP

1.유용한 PHP 함수 모음

  • int strlen(string str);
  • string addslashes(string str); 작은 따옴표나 큰 따옴표, 역슬래시에 해당하는 문자가 있을 경우 그 앞에 역슬래시 문자를 추가
  • string stripslashes(string str): 위의 함수와 반대 역할을 하는 함수로 역슬래시가 있으면 제거
  • string nl2br(string str): 개행문자를 <br> 문자로 변경
  • string number_format(float number [, int decimals]): 숫자를 문자로 변경
  • string substr(string string, int start [, int length]): 문자열의 시작(start)부터 개수(length)만큼 추출해서 반환
  • string strrchr(string str, string needle): needle이 마지막으로 나오는 위치부터 마지막 null 문자까지를 반환
  • string htmlspecialchars(string string [, int quote_style [, string charset]]): html에 관련된 문자를 변경해서 반환
  • string chop(string str [, string charlist]): 문자열 뒤에 남은 공백을 제거해서 반환

 

2.DB에 접속하고 데이터를 얻어오는 코드

  1.     /**
  2.      *  DB에 접속하고 DB 연결
  3.      */
  4.     $link=@mysql_connect("서버 주소", "아이디", "비밀번호") or die ("error");
  5.     printf("접속되었습니다.");
  6.     echo "<br>";
  7.  
  8.     mysql_select_db("데이터 베이스명", $link) or die ("error");
  9.     printf("DB 선택에 성공했습니다.");
  10.     echo "<br>";
  11.  
  12.     $query="SELECT * FROM game WHERE score=100 ORDER BY name DESC LIMIT 100";
  13.     $result = mysql_query($query, $link) or die("error");
  14.  
  15.     /**
  16.      *  점수가 아직 없으면 없다고 출력하고 종료
  17.      */
  18.     echo "<center>";
  19.     if( mysql_num_rows( $result ) == 0 )
  20.     {
  21.         printf("점수가 없습니다.");
  22.     }
  23.     else
  24.     {
  25.         echo "Row의 개수" + mysql_num_rows($result);
  26.         
  27.         echo "점수를 출력합니다 <br>";
  28.  
  29.         $rowcount = mysql_num_rows($result);
  30.         $order = 1;
  31.         for( $i = 0 ; $i < $rowcount ; $i++ )
  32.         {
  33.             $row=mysql_fetch_array($result);
  34.  
  35.             echo "$order $row[id] $row[name]";
  36.  
  37.             $order++;
  38.         }
  39.     }
  40.     exit;

 

 

History

Last edited on 10/23/2010 21:49 by kkamagui

Comments (0)

You must log in to leave a comment. Please sign in.