Study/Mysql

list2.php

zeroplus1 2012. 9. 17. 00:09

<?PHP
//DB연결
$con=mysql_connect("localhost","john","1");

//DB선택
mysql_select_db("johnDB");

//SQL구문
$sql="select * from Member";

//SQL문장 실행
//$res는 질의결과(Active Set-DB메모리공간)를 직접 담고있지는 않고
//Active Set에 도달할 수 있는 메모리 번지를 저장하고 있음
//$res를 사용하면 Active Set에 도달할 수 있다.
$res=mysql_querty($sql); 
$rows=mysql_num_rows($res);//전체 레코드 갯수를 반환


 show();

//DB연결 종료
mysql_close($con);
?>

<?PHP
 function show()
 {
  global $res, $rows; // 나를 호출해준 영역의 메모리 공간을 그대로 사용.(전역변수화 시킴)
  //웹서버 메모리에 실질적인 DB데이터가 없음
echo "<table border='1'>";
$i=0;
while($i<$rows)
{

    $userid=mysql_result($res, $i, 'userid');
    $userage=mysql_result($res, $i, 'userage');
    echo ("
          <tr>
          <td> $userid </td> <td> $userage </td>
          </tr>
         ");
         
          
    $i++;
}
echo "</table>";
 }
?>

 

'Study > Mysql' 카테고리의 다른 글

list3.php  (0) 2012.09.17
PHP DB연결  (0) 2012.09.03
*MY-SQL계정(root) - 사용자 관리  (0) 2012.09.02
DB기초 - 명령어  (0) 2012.09.02