hello eveyone,
Ik was being with a project for my school and now im trying to get data from the database into an html table using php. This is my code now:
<html>
<head>
<title>Algemene gegevens gedetineerden</title>
</head>
<body>
<table border="1" cellpadding="2">
<tr>
<th>ID</strong></th>
<th>Naam</strong></th>
<th>Adres</strong></th>
<th>Geslacht</strong></th>
<th>Telefoon</strong></th>
<th>Email</strong></th>
<th>Woonplaats</strong></th>
<th>Geboortedatum</strong></th>
</tr>
</table>
<?php
/*function mysql_connect(){
};
function mysql_select_db(){
};*/
/*mysql_connect("localhost","root","") or die("geen verbinding met database");
mysql_select_db("pro07") or die("kan database niet vinden");*/
define('HOST','localhost');
define('DATABASE','pro07');
define('USER','root');
define('PASSWORD','');
//stap2-connectie
try{
$conn=mysqli_connect(HOST,USER,PASSWORD,DATABASE);
echo ("connection succeed!");
}
catch(mysqi_sql_exception $e) {
echo $e->getMessage();
exit;
echo "connection failed!";
}
$query="SELECT id,naam,adres,geslacht,telefoon,email,woonplaats,geboortedatum FROM alggegevens;";
/*$query="SELECT * FROM alggegevens;"; >>>vanaf regel 57 alle namen in tabel met hoofdletter,bij query hierboven niet
.hoe je het in de query zet.zo moet het ook inde table rows staan */
function mysql_query(){
};
$resultaat = mysql_query($query);
function mysql_fetch_array(){
};
while ($row = mysql_fetch_array($resultaat)) {
?>
<tr>
<td><?php print($row["id"]); ?></td>
<td><?php print($row["naam"]); ?></td>
<td><?php print($row["adres"]); ?></td>
<td><?php print($row["geslacht"]); ?></td>
<td><?php print($row["telefoon"]); ?></td>
<td><?php print($row["email"]); ?></td>
<td><?php print($row["woonplaats"]); ?></td>
<td><?php print($row["geboortedatum"]); ?></td>
</tr>
<?php
}
/*echo $row;*/
/*echo $resultaat */
?>
</body>
</html>
ive tried to echo te row and the result beacause i saw there was no echo. ive tried the query and it's gooed. the connection is also good. so i'v no idea how to fix this problem. see image for the result i get:only the table header without data. please help me. thanks in advance
CodePudding user response:
You must not close <table>
before you have printed out the data.
Is the data read correctly? If yes, in this case something of the data must be visible. And if not, at least the empty <td>
should be visible in the source code.
CodePudding user response:
Your echo should be inside the while loop like
function mysql_query(){
};
$resultaat = mysql_query($query);
function mysql_fetch_array(){
};
while ($row = mysql_fetch_array($resultaat)) {
//echo here
// echo $resultaat;
echo '<tr>
<td>'.$row["id"].'</td>
</tr>';
?>