2014-06-19 5 views
0

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에 비교적 새로운 해요 이건 내 코드입니다. 아무도 이것으로 나를 도울 수 있습니까? 미리 감사드립니다.

+0

'반환 mysql_select_db ($ 연결)'한가지 :

중 하나는 mysql_fetch_array() 또는 mysql_fetch_assoc()

확인이를 사용합니다. –

+0

@ Fred-ii- : 아니요, 그럴 것입니다. OP가 맞습니다. http://www.php.net/manual/en/function.mysql-select-db.php –

+0

@LightnessRacesinOrbit Duh, 죄송합니다. 나의 실수는 내가 mysql_select_db ($ db, $ connection)를 의미했다는 것이다. –

답변

2

구문 강조 표시와 오류 메시지는 모두 무엇이 잘못되었는지를 알려줍니다.

코드에 일부 " 문자가 누락되었습니다.

+0

OP는'''누락 된 질문을 수정하여 왜 궁금합니다 편집 : 정의되지 않은 색인 –

+0

고마워, @ LightnessRacesinOrbit. $ result에서 오류가 발생했습니다. 정의되지 않은 색인 인 rs1, rs2, rs3, rs4, rs5가 대신 사용해야하는 것은 무엇입니까? – nOOr

+1

나는 하나씩 문제를 겪지 않을 것이므로 SO는 헬프 데스크가 아닙니다. –

관련 문제