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
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)){
...
?>

Link to comment
Share on other sites

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().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.