tijger0407 Posted May 25, 2009 Share Posted May 25, 2009 Currently working on a webpage.The first page works fine with data from the database and shows all results, same code.Second page it should be the same but only shows 1 result, if I change DESC to ASC it shows the other result.Cant figure what is the problem with the code Echo "<h3>Hoofd BHV'ers</h3>"; Echo "<table border='1' cellspacing='0' cellpadding='0'>"; Echo "<tr><th colspan='3'>Naam </th> <th> Email </th> <th> Telefoon vast </th> <th> Telefoon mobiel</th></tr>"; $bhverselecteren = mysql_query("SELECT personeel.PersoneelID, personeel.KantoorID, personeel.Voornaam, personeel.Tussenvoegsel, personeel.Achternaam, personeel.Email, personeel.Telefoonnummer_vast, personeel.Telefoonnummer_mobiel FROM personeel, bhvers, kantoren WHERE personeel.PersoneelID = bhvers.PersoneelID AND personeel.KantoorID = kantoren.KantoorID AND kantoren.Kantoor_plaats = '$kantoorplaats' ORDER BY personeel.Achternaam DESC"); While (list($PersoneelID, $KantoorID, $Voornaam, $Tussenvoegsel, $Achternaam, $Email, $Telefoonnummer_vast, $Telefoonnummer_mobiel) = mysql_fetch_row($bhverselecteren)) { $bhver = "<tr><td>$Voornaam </td> "; $bhver .= " <td>$Tussenvoegsel </td> "; $bhver .= " <td>$Achternaam </td> "; $bhver .= " <td>$Email </td> "; $bhver .= " <td>$Telefoonnummer_vast </td> "; $bhver .= " <td>$Telefoonnummer_mobiel</td></tr>"; } Echo @$bhver; Echo "</table>"; Help is apriciated.Am I missing a loop to give all results or something else. Link to comment Share on other sites More sharing options...
jeffman Posted May 25, 2009 Share Posted May 25, 2009 The problem is this line: $bhver = "<tr><td>$Voornaam </td> "; With every iteration of your while loop, you are reinitializing the value of $bhver -- erasing everything that was assigned to $bhver in the previous initializations. The solution is to initialize $bhver before the loop, and change that = operator to .= just as you have in the lines that follow.It's a common mistake. Link to comment Share on other sites More sharing options...
tijger0407 Posted May 26, 2009 Author Share Posted May 26, 2009 The problem is this line:$bhver = "<tr><td>$Voornaam </td> "; With every iteration of your while loop, you are reinitializing the value of $bhver -- erasing everything that was assigned to $bhver in the previous initializations. The solution is to initialize $bhver before the loop, and change that = operator to .= just as you have in the lines that follow.It's a common mistake. Thanks for the help.initializing the variable before the while statement fixed the problem Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.