andrew6607 Posted February 22, 2008 Share Posted February 22, 2008 Hello, I can not figure out how to fix this problem. I am trying to get data from mysql. I have 3 records in the table but it will only display one. Below is the code. <?php $Host = "localhost"; $User = "root"; $Password = "******"; $DBName = "website"; $TableName = "members"; $Conn = mysql_connect ($Host, $User, $Password) or die ( "MySQL Error!" ); //now lets do the query $Query = "SELECT * from $TableName"; $Result = mysql_db_query ($DBName, $Query, $Conn) or die ( "MySQL Error 2!" ); $data=mysql_fetch_assoc($Result); ?> <table border="1" align="center"> <tr> <td>First Name</td><td>Last Name</td><td>Email</td><td>User Level</td><td>Delete</td><td>Edit User</td> </tr> <tr> <td><?php echo $data['fname']; ?></td><td><?php echo $data['lname']; ?></td><td><?php echo $data['email']; ?></td><td><?php echo $data['level']; ?></td><td><a href="delete.php?fname=<?php echo $data['fname']; ?>">Delete User</a></td><td><a href="edit.php?fname=<?php echo $data['fname']; ?>">Edit User</a></td> </tr> </table> Thank you ahead of time! Quote Link to comment Share on other sites More sharing options...
drisate Posted February 22, 2008 Share Posted February 22, 2008 use this <?php $Query = mysql_query("SELECT * from $TableName") or die (mysql_error()); if (mysql_num_rows($Query)) { while ($data = mysql_fetch_array($Query)) { ?> <table border="1" align="center"> <tr> <td>First Name</td><td>Last Name</td><td>Email</td><td>User Level</td><td>Delete</td><td>Edit User</td> </tr> <tr> <td><?php echo $data['fname']; ?></td><td><?php echo $data['lname']; ?></td><td><?php echo $data['email']; ?></td><td><?php echo $data['level']; ?></td><td><a href="delete.php?fname=<?php echo $data['fname']; ?>">Delete User</a></td><td><a href="edit.php?fname=<?php echo $data['fname']; ?>">Edit User</a></td> </tr> </table> <?php } } ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 22, 2008 Share Posted February 22, 2008 You need to use a while loop, like this: <?php $Host = "localhost"; $User = "root"; $Password = "******"; $DBName = "website"; $TableName = "members"; $Conn = mysql_connect ($Host, $User, $Password) or die ( "MySQL Error!" ); //now lets do the query $Query = "SELECT * from $TableName"; $Result = mysql_db_query ($DBName, $Query, $Conn) or die ( "MySQL Error 2!" ); ?> <table border="1" align="center"> <tr> <td>First Name</td><td>Last Name</td><td>Email</td><td>User Level</td><td>Delete</td><td>Edit User</td> </tr> <?php while ($data=mysql_fetch_assoc($Result)){ echo '<tr>'; echo "<td>{$data['fname']}</td><td>{$data['lname']}</td><td>{$data['email']}</td><td>{$data['level']}</td> <td><a href='delete.php?fname={$data['fname']}'>Delete User</a></td> <td><a href='edit.php?fname={$data['fname']}'>Edit User</a></td>"; echo '</tr>'; } ?> </table> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.