Jump to content

SELECT Function not showing all


Knuckles

Recommended Posts

When i use this code it show everything except for the first record in the table. I have also tried it with the users for the login system im using and then it doesnt show the person im logged in to or also the first record in the table and i need it too show all the records

 

How do i solve this? I thought it had something to do with:

 

                                                                             <?php while ($rij = mysql_fetch_array($result)){
											echo ("<tr><td>". $rij['ID'] . " </td> " .
											"<td>" . $rij['naam'] . " " . 
											$rij['telefoon'] . " </td> " .
											"<td>" . $rij['adres'] . " </td> " .
											"<td>" . $rij['mobiel`'] . " </td>".
											"</td></tr>\n ");	
											}
										?>

 

But i dont know how to solve it.

 

                                                                       <?php
									$con = mysql_connect("localhost","root","");
										if (!$con)
											{
										die('Could not connect: ' . mysql_error());
											}


									mysql_select_db("root123", $con);

										$sql= "SELECT * FROM root123 ORDER BY ID;";
										$result = mysql_query($sql, $con);
										$rij = mysql_fetch_array($result);

									?>

									<table width="80%" align="center">
										<tr>
											<th>ID</th>
											<th width="150px">Naam</th>
											<th>Gebruikersnaam</th>
											<th width="300px">Wachtwoord</th>

										</tr>
										<?php while ($rij = mysql_fetch_array($result)){
											echo ("<tr><td>". $rij['ID'] . " </td> " .
											"<td>" . $rij['naam'] . " " . 
											$rij['telefoon'] . " </td> " .
											"<td>" . $rij['adres'] . " </td> " .
											"<td>" . $rij['mobiel`'] . " </td>".
											"</td></tr>\n ");	
											}
										?>
									</table>

Link to comment
https://forums.phpfreaks.com/topic/233700-select-function-not-showing-all/
Share on other sites

Ah, my spidey sense was right again.

 

$rij = mysql_fetch_array($result);

Get rid of that.

 

Just to clarify, removing the first mysql_fetch_array() call should fix the issue.

 

<?php
...

$sql= "SELECT * FROM root123 ORDER BY ID;";
$result = mysql_query($sql, $con);
$rij = mysql_fetch_array($result);  //<--- REMOVE THIS ONE

...

while ($rij = mysql_fetch_array($result)){
...
?>

As a side note, according to the mysql_query() function description the query string shouldn't end with a semicolon:

http://php.net/manual/en/function.mysql-query.php

 

 

<?php

//OLD CODE
$sql= "SELECT * FROM root123 ORDER BY ID;";

//CHANGE TO
$sql= "SELECT * FROM root123 ORDER BY ID";

?>

 

 

With that said, PHP doesn't seem to throw any errors or warnings for the extra semicolon. I also don't see any errors with mysql_error().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.