Monday, 15 July 2013

php - Error displaying table from database -



php - Error displaying table from database -

i'm trying display table, t2d_10 database, chr10 using php. table has 5 columns rs1, rs2, rs3, rs4, rs5. code:

<?php // set database server access variables: $host = "localhost"; $user = "root"; $pass = ""; $db = "chr10"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("unable connect!"); // select database mysql_select_db($db, $connection) or die ("unable select database!"); // create query $query = "select * t2d_10"; // execute query $result = mysql_query($query) or die ("error in query: $query. ".mysql_error()); // see if rows returned if (mysql_num_rows($result) > 0) { // yes // print them 1 after 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); ?>

error:

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

i'm new php. can please help me this? in advance.

mysql_fetch_row() indexed array only.

either utilize mysql_fetch_array() or mysql_fetch_assoc()

check this: difference between mysql_fetch_array , mysql_fetch_row?

php database

No comments:

Post a Comment