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.   // 레코드 포인터 2개 이동
  16.   mysql_data_seek($sql_r, 2);
  17.   // 검색결과의 레코드 하나씩 출력
  18.   $count = 1;
  19.   while($row = mysql_fetch_array($sql_r)){
  20.     $i = 1;
  21.     $field = "";
  22.     foreach($row as $value){
  23.       switch($i){
  24.       // 필드명
  25.         case 1: $field = "no";
  26.         break;
  27.         case 2: $field = "title";
  28.         break;
  29.         case 3: $field = "content";
  30.         break;
  31.         case 4: $field = "writer";
  32.         break;
  33.         case 5: $field = "savedate";
  34.         break;
  35.         case 6: $field = "hit";
  36.         break;
  37.         default: echo "에러"; die();
  38.         break;
  39.       } // switch문 끝
  40.       // 레코드 출력
  41.       echo " $field : $row[$field] ";
  42.       // 필드 3개 까지
  43.       if($i == 4) break;
  44.       else echo "||"; 
  45.       $i++;
  46.     } // foreach문 끝
  47.     echo "<br>\n";
  48.     $count++;
  49.     // 레코드 8개 까지
  50.     if($count == 9) break;
  51.   } // while문 끝
  52.   if(!mysql_close($mysql_con)) echo "연결 종료 실패";
  53.   /*레코드 출력
  54.      no : 3 || title : test_title 3 || content : test content 3 || writer : test1 
  55.      no : 4 || title : test_title 4 || content : test content 4 || writer : test1 
  56.      no : 5 || title : test_title 5 || content : test content 5 || writer : test1 
  57.      no : 6 || title : test_title 6 || content : test content 6 || writer : test1 
  58.      no : 7 || title : test_title 7 || content : test content 7 || writer : test1 
  59.      no : 8 || title : test_title 8 || content : test content 8 || writer : test1 
  60.   */
  61. ?>

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


bool mysql_data_seek ( resource $result , int $row_number )


16. 라인

$result의 레코드 포인터의 위치를 이동이 성공시 TRUE값을 반환합니다.

실패시 FALSE 값을 반환합니다.

(no3부터 출력)


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/03   »
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
31
Total :
Today : Yesterday :