 |
|
|  |
| html에서 입력한값 DB에서 받아오기 (도서정보 검색) |
|
|
 |
10년 전 |
book_search.html(도서정보)
book_insert.php
book_list.php
1. book_search.html(도서정보) (html에서 도서정보 입력)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
<title>도서검색</title>
</head>
<body>
<p><h3>도서정보 검색하기</h3></p>
<form action='book_search.php' method='post'>
<select name='searchtype'>
<option value='title'>도서명</option>
<option value='author'>저자</option>
<option value='publisher'>출판사</option>
<option value='isbn'>일련번호</option>
</select>
<br/>
<input type='text' name='searchterm' size='40'/>
<input type='submit' value='검색' />
</form>
</body>
</html>
----------------
2. book_search.php (html에서 입력한값 DB에서 불러와서 php로 뿌려주기
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
<?
$connect = mysql_connect("localhost","wooin","1234");
$db_con=mysql_select_db("wooin_db",$connect);
$query = "select * from book where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query, $connect);
$records = mysql_num_rows($result); // mysql_num_rows 인자의 레코드 개수를 알려준다
$fields=mysql_num_fields($result); // mysql_num_fields인자의 필드개수를 알려준다
echo "<p> 관련도서를 ".$records."개 찾았습니다.</p>";
$number=1;
?>
<h2> 도서정보 검색결과</h2>
<table width ="800" border="1" cellspacing="0" cellpadding="5">
<tr align="center">
<td bgcolor="#cccccc">순번</td>
<td bgcolor="#cccccc">도서명</td>
<td bgcolor="#cccccc">저자</td>
<td bgcolor="#cccccc">출판사</td>
<td bgcolor="#cccccc">주소</td>
<td bgcolor="#cccccc">가격</td>
<td bgcolor="#cccccc">일련번호</td>
</tr>
<?
for($i =0; $i < $records; $i++){
echo"<tr align='center'>>";
echo"<td>$number </td>";
for($j=0; $j< $fields; $j++){
$data = mysql_result ($result, $i, $j); // 레코드위 특정위치에 저장된 값을 가져온다
echo "<td> $data</td>";
}
echo"<tr>";
$number++;
}
mysql_close();
?> |
|
추천 : 814 |
추천
목록
|
|
|  |
|