<html>
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
$username ="matt";
$pass = "bs12kfj";
$db = "mytest";
$tbl = "test2";
mysql_connect(localhost,$username,$pass);
mysql_select_db($db) or die( "Unable to select database");
$res = mysql_query("SELECT * FROM test2;");
$num = mysql_numrows($res);
echo "<table border='2'><tr>The Peeps</tr>";
while ($r = mysql_fetch_array($res)) {
echo "<tr>";
foreach($r as $rs){
echo "<td>$rs</td>";
}
echo "</tr>";
}
?>
</body>
Bu kod hatasız yürütür ama çıkış öylesine gibi her satırın her sütunun bir kopyasını içerir.
<table border='2'><tr>The Peeps</tr>
<tr><td>"matt"</td><td>"matt"</td><td>"phillips"</td><td>"phillips></td><td>"mathew.p@waburg.com"</td><td>"mathew.p@waburg.com"</td><td>20</td><td>20</td></tr><tr><td>"paul"</td><td>"paul"</td><td>"franklin"</td><td>"franklin"</td><td>"dude@live.com"</td><td>"dude@live.com"</td><td>30</td><td>30</td></tr><tr><td>"steve"</td><td>"steve"</td><td>"jobs"</td><td>"jobs"</td><td>"sjobs@apple.com"</td><td>"sjobs@apple.com"</td><td>23</td><td>23</td>
I don't understand why each column is duplicated when there is only a single <td></td>
tag in the echo statement.
I also checked the db and the table does not contain duplicate entries.