게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
php고수분들 도와주세요
게시물ID : jisik_78051짧은주소 복사하기
작성자 : 강두
추천 : 1
조회수 : 648회
댓글수 : 3개
등록시간 : 2010/06/03 00:07:34
---------------------list.php 파일(목록)소스---------------------------------

<? 

$con=mysql_connect("localhost","root","123"); 

$db=mysql_select_db("sbcsi",$con); 
$sql="select * from phpboard order by num desc";    // 가장 최근글이 위로 올라오도록함, read.php에 num을 가지고 들어감

$result=mysql_query($sql,$con); 




$numrows=mysql_num_rows($result); // result의 결과값의 내용의 갯수를 구한다 0이라면 자료가 없는것이다




?> 
<html> 
<head> 
<title>찬우 게시판</title> 
</head> 
<body> 
<center><h1>게시판</h1></center><br> 
<table border=1 align=center width=680> 
<tr> 
<td colspan=3 align=center>게시판</td> 
</tr> 
<tr> 
<td>번호</td><td>제목</td><td>작성자</td> 
</tr> 
<? 
if($numrows!=0) // 자료가 있다면 0이 아니라면 자료가 있다는 의미이다

for($i=1; $i<=$numrows; $i++) // 자료 수만큼 $i값을 반복한다

$rows=mysql_fetch_array($result); // rows에 자료를 배열로 나누어서 변수에 어사인 시킨다
$num=$rows[num]; 
$subject=$rows[subject]; 
$name=$rows[name]; 
$content=$rows[content]; 



?> 
<tr> 
<!-- 실제 출력문 시작 -->
<td><?=$num?></td><td><a href="read.php?num=<?=$num?>"><?=$subject?></a></td><td><?=$name?></td>
<!-- 실제 출력문 끝 -->
</tr> 
<? 
} // end for 게시물 있는 것 만큼 돈다 mysql_fetch_array 로 배열처리하여 출력한다 
} // end if numrows 게시물이 없으면 if문 
?> 
</table><br><br>
<center><a href="write.php">글쓰기</a></center> 

</body> 
</html> 


---------------------read.php(글내용) 파일소스---------------------------------
<?

$con=mysql_connect("localhost","root","123"); 
$db=mysql_select_db("sbcsi",$con);

$sql="select * from phpboard  where num=$num";
$result=mysql_query($sql,$con); 

$numrows=mysql_num_rows($result);
$rows=mysql_fetch_array($result);



$name=$rows[name]; 
$subject=$rows[subject]; 
$content=nl2br(htmlspecialchars($rows[content]));
?> 

<html>
<head> 
<title>red</title> 
</head> 
<body> 
<table border=1 align=center width=680> 
<tr> 
<td width=80>num</td><td width=600><?=$num?></td> 
</tr> 
<tr> 
<td width=80>name</td><td width=600><?=$name?></td> 
</tr> 
<tr> 
<td width=80>subject</td><td width=600><?=$subject?></td> 
</tr> 
<tr> 
<td width=80>content</td><td width=600><?=$content?></td> 
</tr> 
</table> 
<center><a href="list.php">list</a></center> 
</body> 
</html>


list.php에서 원하는글에 접속했을때

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\APM_Setup\htdocs\read.php on line 10

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\APM_Setup\htdocs\read.php on line 11
이런 에러가 뜹니다

어디에 문제가 있는걸까요
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호