솔직히....정상적으로 php를 공부한것이 아니기 때문에...알고 있는 부분만 적습니다.
다른 방법도 존재할것이고...더 좋은 방법이 있지만....아는 부분까지만 올릴게요
DB에서 값을 불러올때는
$sql = " select * from g4_member where mb_1 = '남자' order by mb_id limit 10 ";
$result = sql_query($sql);
$result = sql_query($sql);
$row=sql_fetch_array($result);
이런식으로 표현을 합니다.
하나하나 짚어보자면
select * from g4_member where mb_1 = '남자' order by mb_id limit 10
이것이 DB에 연결해서 데이터를 불러오도록 설정하는 것입니다
* 는 g4_memmber 테이블에 있는 모든 필드값을 불러오라는 것이고
where mb_1 = '남자' 는 조건을 주어서 조건에 맞는 것만 불러오도록 하는 것입니다. mb_1 필드값이 '남자' 인 게시물을 찾으라는 것이지요
order by 는 게시물을 불러왔을때 정렬해 주는 것이고
limit 는 불러오는 갯수를 정해주는 것입니다.
이제 쉽죠...??
데이터가 있을때 원하는 부분만 불러올때는 저런식으로 값을 넣어서...불러오면 됩니다.
예를 들어 회원레벨이 5에서 7인 회원데이터를 불러오고자 할때에는
select * from g4_member where mb_level >= '5' and mb_level <= '7' 이런식으로 조건을 넣어주면 됩니다.
보시면 알겠지만 mb_level >= '5' and mb_level <= '7' 조건부분에 두가지 내용이 들어가 있죠??
두개다 만족하는 게시물을 찾을때에는 and를 넣어주면 되고 둘중에 한조건만 만족을 주는 것을 찾을때에는
or를 넣어주면 됩니다. and와 or는 완전히 다른 의미입니다
select * from g4_member where mb_level >= '5' or mb_level <= '7'
이렇게 되면 회원레벨이 5이상인 회원을 다 불러오는 것이고 또 7이하인 회원을 다 불러오는 것이기 때문에 결국 회원전체를 불러오게 되는 조건이 되어 버립니다.
select * from g4_member where mb_level = '5' and mb_level = '7'
이렇게 넣어주면 회원레벨이 5이면서 7인 회원을 불러오라고 하는 것입니다.....말이 이상하죠??...결국 데이터가 아무것도 없게되죠?
근데? 한가지 이상하죠?
php구문에서는 == 가 같다는 의미였는데..db불러올때에는 = 가 한개가 들어갑니다...이유는...저도 몰라요..그렇게 씁니다...두개 들어가면 에러나요...ㅜㅜ
그리고
$row=sql_fetch_array($result); 부분이 있습니다.
$row가 값을 표현해주는 방식입니다
<?=$row[mb_1]?>
이렇게 불러와 주시면 됩니다.
$row_mb=sql_fetch_array($result); 이렇게 하면
<?=$row_mb[mb_1]?> 이렇게 되겠죠???
그리고
게시물의 갯수를 구할때에는
$sql_cnt = " select count(*) as cnt from g4_member where mb_1 = '남자'";
$row_cnt = sql_fetch($sql_cnt);
$total_count = $row_cnt[cnt];
$row_cnt = sql_fetch($sql_cnt);
$total_count = $row_cnt[cnt];
이렇게 처리하면 됩니다. g4_member 테이블에서 $mb_1 값이 남자인 게시물의 게수를 구하는 것이지요
$total_count 값이 그 값입니다.
order by mb_1 asc
는 데이터 정렬 방식인데 asc는 오름차순을 뜻하며, 일반적으로 생략합니다.
그리고 desc는 내림차순을 뜻하는 거구여. 생략할 수 없습니다.
order by mb_1 desc mb_1 값을 기준으로 내림차순으로 정렬하는 것이지요
보통 게시판 리스트에서는 게시물이 많이 때문에 for 문을 이용하여 불어옵니다.
<?php
$sql = " select * from g4_member where mb_1 = '남자' order by mb_id limit 10 ";
$result = sql_query($sql);
$result = sql_query($sql);
?>
<table width=100% cellpadding=0 cellspacing=0>
<tr>
<td class='biz_bbs_left'></td>
<td class='biz_bbs_bg' width=90><b>게시판아이디</td>
<td class='biz_bbs_bg'><b>게시판이름</td>
<td class='biz_bbs_bg' width=80><b>게시판스킨</td>
<td class='biz_bbs_bg' width=80><b>카테고리사용</td>
<td class='biz_bbs_bg' width=80><b>읽기권한</td>
<td class='biz_bbs_bg' width=80><b>쓰기권한</td>
<td class='biz_bbs_bg' width=50><b>삭제</td>
<td class='biz_bbs_bg' width=50><b>보기</td>
<td class='biz_bbs_right'></td>
</tr>
<?
for ($i=0; $row=sql_fetch_array($result); $i++) {
$list = $i%2;
<tr>
<td class='biz_bbs_left'></td>
<td class='biz_bbs_bg' width=90><b>게시판아이디</td>
<td class='biz_bbs_bg'><b>게시판이름</td>
<td class='biz_bbs_bg' width=80><b>게시판스킨</td>
<td class='biz_bbs_bg' width=80><b>카테고리사용</td>
<td class='biz_bbs_bg' width=80><b>읽기권한</td>
<td class='biz_bbs_bg' width=80><b>쓰기권한</td>
<td class='biz_bbs_bg' width=50><b>삭제</td>
<td class='biz_bbs_bg' width=50><b>보기</td>
<td class='biz_bbs_right'></td>
</tr>
<?
for ($i=0; $row=sql_fetch_array($result); $i++) {
$list = $i%2;
echo "
<tr>
<td height=35></td>
<td align=center><b>$row[bbs_id]</td>
<td align=center>$row[bbs_name]</td>
<td align=center>$row[bbs_skin]</td>
<td align=center>$checked</td>
<td align=center>".get_biz_level("$row[biz_id]", $row[bbs_read_level])."[$row[bbs_read_level]]</td>
<td align=center>".get_biz_level("$row[biz_id]", $row[bbs_write_level])."[$row[bbs_write_level]]</td>
<td align=center>$s_del</td>
<td align=center>$s_mod</td>
<td></td>
</tr>
<tr><td colspan='$colspan' class='biz_bbs_line2'></td></tr>";
}
<tr>
<td height=35></td>
<td align=center><b>$row[bbs_id]</td>
<td align=center>$row[bbs_name]</td>
<td align=center>$row[bbs_skin]</td>
<td align=center>$checked</td>
<td align=center>".get_biz_level("$row[biz_id]", $row[bbs_read_level])."[$row[bbs_read_level]]</td>
<td align=center>".get_biz_level("$row[biz_id]", $row[bbs_write_level])."[$row[bbs_write_level]]</td>
<td align=center>$s_del</td>
<td align=center>$s_mod</td>
<td></td>
</tr>
<tr><td colspan='$colspan' class='biz_bbs_line2'></td></tr>";
}
if ($i == 0)
echo "<tr><td colspan='$colspan' align=center height=150>자료가 없습니다.</td></tr>";
echo "<tr><td colspan='$colspan' align=center height=150>자료가 없습니다.</td></tr>";
echo "<tr><td colspan=$colspan class='biz_bbs_line2'></td></tr>
</table>";
</table>";
?>
이런식으로 해서 해당값을 가지는 게시물만 불러와서 보여주는 것입니다.
참 쉽죠????
댓글 6개
13년 전
좋은 정보를 이행하기 쉽게 올려주시는 분들이있어 초보자들이 편하겠네요.. ^^
13년 전
감사합니다
13년 전
$list = $i%2;
이부분의 설명이 있을줄 알았는데 ㅠㅠ 아쉽지만 잘보고 가요 ^^
이부분의 설명이 있을줄 알았는데 ㅠㅠ 아쉽지만 잘보고 가요 ^^
13년 전
감사합니다.ㅎ
takumi22
12년 전
잘봤습니다
10년 전
테이블에 특정 id값이 있는지 검사하는 구문을 찾고 있었는데..
이곳에서 힌트를 얻었습니다.
좋은정보 감사합니다^^
이곳에서 힌트를 얻었습니다.
좋은정보 감사합니다^^
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4530 |
라이언31
|
13년 전 | 650 | |
| 4529 | 13년 전 | 807 | ||
| 4528 |
꼬꼬아부지
|
13년 전 | 1009 | |
| 4527 | 13년 전 | 619 | ||
| 4526 | 13년 전 | 701 | ||
| 4525 |
|
13년 전 | 1026 | |
| 4524 | 13년 전 | 1002 | ||
| 4523 | 13년 전 | 2298 | ||
| 4522 | 13년 전 | 616 | ||
| 4521 | 13년 전 | 1264 | ||
| 4520 | 13년 전 | 1553 | ||
| 4519 |
복이219
|
13년 전 | 1208 | |
| 4518 | 13년 전 | 497 | ||
| 4517 | 13년 전 | 1298 | ||
| 4516 |
아이피마스터
|
13년 전 | 557 | |
| 4515 | 13년 전 | 653 | ||
| 4514 | 13년 전 | 650 | ||
| 4513 | 13년 전 | 1083 | ||
| 4512 |
ananom
|
13년 전 | 4367 | |
| 4511 |
ananom
|
13년 전 | 1482 | |
| 4510 | 13년 전 | 1225 | ||
| 4509 | 13년 전 | 692 | ||
| 4508 | 13년 전 | 851 | ||
| 4507 | 13년 전 | 938 | ||
| 4506 | 13년 전 | 709 | ||
| 4505 | 13년 전 | 639 | ||
| 4504 | 13년 전 | 483 | ||
| 4503 | 13년 전 | 526 | ||
| 4502 |
|
13년 전 | 1814 | |
| 4501 | 13년 전 | 1647 | ||
| 4500 |
|
13년 전 | 517 | |
| 4499 | 13년 전 | 1898 | ||
| 4498 | 13년 전 | 1161 | ||
| 4497 |
미션임파썩을
|
13년 전 | 894 | |
| 4496 | 13년 전 | 947 | ||
| 4495 |
공포의니이킥
|
13년 전 | 1116 | |
| 4494 | 13년 전 | 1979 | ||
| 4493 | 13년 전 | 1066 | ||
| 4492 | 13년 전 | 490 | ||
| 4491 |
두근두근따봉
|
13년 전 | 927 | |
| 4490 | 13년 전 | 1369 | ||
| 4489 |
jaein8060
|
13년 전 | 619 | |
| 4488 | 13년 전 | 1048 | ||
| 4487 |
ReeJang
|
13년 전 | 1826 | |
| 4486 | 13년 전 | 990 | ||
| 4485 | 13년 전 | 811 | ||
| 4484 | 13년 전 | 858 | ||
| 4483 | 13년 전 | 524 | ||
| 4482 | 13년 전 | 1184 | ||
| 4481 | 13년 전 | 1053 | ||
| 4480 |
|
13년 전 | 527 | |
| 4479 | 13년 전 | 918 | ||
| 4478 | 13년 전 | 3971 | ||
| 4477 | 13년 전 | 992 | ||
| 4476 |
wangko
|
13년 전 | 2711 | |
| 4475 | 13년 전 | 933 | ||
| 4474 | 13년 전 | 961 | ||
| 4473 | 13년 전 | 766 | ||
| 4472 |
|
13년 전 | 561 | |
| 4471 | 13년 전 | 1568 | ||
| 4470 | 13년 전 | 576 | ||
| 4469 | 13년 전 | 530 | ||
| 4468 | 13년 전 | 864 | ||
| 4467 | 13년 전 | 660 | ||
| 4466 | 13년 전 | 924 | ||
| 4465 | 13년 전 | 673 | ||
| 4464 | 13년 전 | 1731 | ||
| 4463 |
chongho
|
13년 전 | 2187 | |
| 4462 |
chongho
|
13년 전 | 1033 | |
| 4461 |
chongho
|
13년 전 | 1032 | |
| 4460 | 13년 전 | 757 | ||
| 4459 | 13년 전 | 2784 | ||
| 4458 | 13년 전 | 790 | ||
| 4457 | 13년 전 | 508 | ||
| 4456 | 13년 전 | 1342 | ||
| 4455 | 13년 전 | 1746 | ||
| 4454 | 13년 전 | 723 | ||
| 4453 | 13년 전 | 1260 | ||
| 4452 |
aequum
|
13년 전 | 1275 | |
| 4451 | 13년 전 | 1341 | ||
| 4450 |
도토리과자
|
13년 전 | 1438 | |
| 4449 | 13년 전 | 1093 | ||
| 4448 | 13년 전 | 8627 | ||
| 4447 | 13년 전 | 1212 | ||
| 4446 | 13년 전 | 1495 | ||
| 4445 | 13년 전 | 648 | ||
| 4444 |
|
13년 전 | 614 | |
| 4443 | 13년 전 | 704 | ||
| 4442 |
Msoft
|
13년 전 | 1064 | |
| 4441 |
|
13년 전 | 2111 | |
| 4440 | 13년 전 | 620 | ||
| 4439 | 13년 전 | 1657 | ||
| 4438 |
aequum
|
13년 전 | 1847 | |
| 4437 | 13년 전 | 997 | ||
| 4436 | 13년 전 | 925 | ||
| 4435 |
디귿소프트
|
13년 전 | 523 | |
| 4434 | 13년 전 | 1076 | ||
| 4433 | 13년 전 | 998 | ||
| 4432 | 13년 전 | 861 | ||
| 4431 | 13년 전 | 760 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기