1. <?php
  2.   // 연결
  3.   $mysql_con = mysql_connect("localhost", "test1", "test1") 
  4.                       or die('Could not connect: ' . mysql_error());
  5.   
  6.   // DB선택
  7.   if(!mysql_select_db("testdb", $mysql_con)) echo "DB 선택 실패";
  8.   
  9.   // character set 설정
  10.   if(mysql_client_encoding($mysql_con) != "utf8")
  11.   mysql_query("SET NAMES 'utf8'");
  12.   
  13.   // board 테이블의 데이터 모두 검색
  14.   $sql_r = mysql_query("SELECT * FROM  `board`");
  15.   $field = "";
  16.   //레코드 수 만큼 반복
  17.   for($i = 0; $i < mysql_num_rows($sql_r); $i++){
  18.     //필드 수 만큼 반복
  19.     for($j = 0; $j < mysql_num_fields($sql_r); $j++){
  20.       switch($j){
  21.         // 필드명
  22.         case 0: $field = "no";
  23.         break;
  24.         case 1: $field = "title";
  25.         break;
  26.         case 2: $field = "content";
  27.         break;
  28.         case 3: $field = "writer";
  29.         break;
  30.         case 4: $field = "savedate";
  31.         break;
  32.         case 5: $field = "hit";
  33.         break;
  34.         default: echo "에러"; die();
  35.         break;
  36.       } // switch문 끝
  37.       echo "$field : ".mysql_result($sql_r,$i,$j)." ";
  38.       // 필드 3개 까지
  39.       if($j == 3) break;
  40.     } // for 문 끝($j)
  41.     echo "<br>\n";
  42.     // 레코드 8개 까지
  43.     if($i == 8) break;
  44.   } // for 문 끝($i)
  45.   if(!mysql_close($mysql_con)) echo "연결 종료 실패";
  46.   /*레코드 출력
  47.      no : 1 || title : test_title 1 || content : test content 1 || writer : test1 
  48.      no : 2 || title : test_title 2 || content : test content 2 || writer : test1 
  49.      no : 3 || title : test_title 3 || content : test content 3 || writer : test1 
  50.      no : 4 || title : test_title 4 || content : test content 4 || writer : test1 
  51.      no : 5 || title : test_title 5 || content : test content 5 || writer : test1 
  52.      no : 6 || title : test_title 6 || content : test content 6 || writer : test1 
  53.      no : 7 || title : test_title 7 || content : test content 7 || writer : test1 
  54.      no : 8 || title : test_title 8 || content : test content 8 || writer : test1 
  55.   */
  56. ?>

--------------------------------------------------------------------------------------------


string mysql_result ( resource $result , int $row [, mixed $field = 0 ] )


37. 라인

$result에서 $row번째 레코도의 $field번째 필드 데이터값을 문자열 반환합니다.


board 테이블 입니다.(아래는 필드명과 데이터 입니다.)


 no

title 

content 

writer 

savedate 

hit 

 1

 test_title 1

 test content 1

 test1

 2013-12-16 00:07:43

 0

 2

 test_title 2

 test content 2

 test1

 2013-12-16 00:07:43

 0

 3

 test_title 3

 test content 3

 test1

 2013-12-16 00:07:43

 0

 4

 test_title 4

 test content 4

 test1

 2013-12-16 00:07:43

 0

 5

 test_title 5

 test content 5

 test1

 2013-12-16 00:07:43

 0

 6

 test_title 6

 test content 6

 test1

 2013-12-16 00:07:43

 0

 7

 test_title 7

 test content 7

 test1

 2013-12-16 00:07:43

 0

 8

 test_title 8

 test content 8

 test1

 2013-12-16 00:07:43

 0

 9

 test_title 9

 test content 9

 test1

 2013-12-16 00:07:43

 0

 10

 test_title 10

 test content 10

 test1

 2013-12-16 00:07:43

 0

 11

 test_title 11

 test content 11

 test1

 2013-12-16 00:07:43

 0

 12

 test_title 12

 test content 12

 test1

 2013-12-16 00:07:43

 0

 13

 test_title 13

 test content 13

 test1

 2013-12-16 00:07:43

 0

 14

 test_title 14

 test content 14

 test1

 2013-12-16 00:07:43

 0

 15

 test_title 15

 test content 15

 test1

 2013-12-16 00:07:43

 0

 16

 test_title 16

 test content 16

 test1

 2013-12-16 00:07:43

 0

 17

 test_title 17

 test content 17

 test1

 2013-12-16 00:07:43

 0

 18

 test_title 18

 test content 18

 test1

 2013-12-16 00:07:43

 0

 19

 test_title 19

 test content 19

 test1

 2013-12-16 00:07:43

 0

 20

 test_title 20

 test content 20

 test1

 2013-12-16 00:07:43

 0



:
BLOG main image

공지사항

카테고리

분류 (356)
main (1)
php5 (218)
HTML (36)
javascript (93)
IT 이론과 퍼온정보 (8)
깨작일상 (0)
곧 추가할 내용 (0)
추후 알아볼것들... (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

달력

«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Total :
Today : Yesterday :