PHP를 사용하여 데이터베이스, chr10에서 t2d_10 테이블을 표시하려고합니다. 내 테이블에는 rs1, rs2, rs3, rs4, rs5 인 5 개의 열이 있습니다.데이터베이스에서 테이블을 표시하는 중 오류가 발생했습니다.
<?php
// set database server access variables:
$host = "localhost";
$user = "root";
$pass = "";
$db = "chr10";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db, $connection) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM t2d_10";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row['rs1']."</td>";
echo "<td>".$row['rs2']."</td>";
echo "<td>".$row['rs3']."</td>";
echo "<td>".$row['rs4']."</td>";
echo "<td>".$row['rs5']."</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
오류 :
Notice: Undefined index: rs1 in C:\wamp\www\ch\run_db.php on line 28
Notice: Undefined index: rs2 in C:\wamp\www\ch\run_db.php on line 29
Notice: Undefined index: rs3 in C:\wamp\www\ch\run_db.php on line 30
Notice: Undefined index: rs4 in C:\wamp\www\ch\run_db.php on line 31
Notice: Undefined index: rs5 in C:\wamp\www\ch\run_db.php on line 32
나는이 PHP에 비교적 새로운 해요 이건 내 코드입니다. 아무도 이것으로 나를 도울 수 있습니까? 미리 감사드립니다.
'반환 mysql_select_db ($ 연결)'한가지 :
중 하나는
mysql_fetch_array()
또는mysql_fetch_assoc()
확인이를 사용합니다. –
@ Fred-ii- : 아니요, 그럴 것입니다. OP가 맞습니다. http://www.php.net/manual/en/function.mysql-select-db.php –
@LightnessRacesinOrbit Duh, 죄송합니다. 나의 실수는 내가 mysql_select_db ($ db, $ connection)를 의미했다는 것이다. –