Tom8001 Posted December 5, 2014 Share Posted December 5, 2014 I have used $sql = "SELECT id, username FROM $tbl_name ORDER BY username"; $result = $con->query($sql); while ($row = $result->fetch_assoc()) { echo "<a href='editUser.php?id={$row['id']}'>{$row['username']}</a><br><br>\n"; echo "<style>a {color: blue; text-decoration: none;} a:hover {color: #ff0000} body {background-color: #000;} </style>"; } in euser.php which echo's out all the users in the database via an anchor tag and includes their id in the url. but when i click on their name i want to have options like: - change password - ban user e.t.c and i have tried $sql = "SELECT id FROM $tbl_name"; $result = $con->query($sql); while ($row = $result->fetch_assoc()) { echo "<a href='editUser.php?id={$row['id']}'> Change Password </a> in my other page editUser.php it posts Change Password Change Password Change Password and each change password has the 3 ids of the users this is confusing me. Quote Link to comment Share on other sites More sharing options...
jcbones Posted December 5, 2014 Share Posted December 5, 2014 Adding a break rule would separate put each anchor onto a new line. echo "<a href='editUser.php?id={$row['id']}'> Change Password </a><br />"; Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted December 5, 2014 Author Share Posted December 5, 2014 I know but, in the file euser.php it looks like this And editUser.php looks like this Now the 3 change password links are each for a user, when i only want a change password link with the current users id that i have clicked on, if that makes any sense? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 5, 2014 Share Posted December 5, 2014 Define you styles once in the <head>..</head> section of your page, not every time you output something to the page. eg <html> <head> <style> a { color: blue; text-decoration: none; } a:hover { color: #ff0000; } body { background-color: #000; } </style> </head> or put the styles in an external .css file. Having linked to "edituser.php?id=1" passing the id of the selected user, why would you then run a query to get the ids of all the users again? Get the details of the selected user for editing (ie. change password, set a flag to ban them etc.) Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted December 5, 2014 Author Share Posted December 5, 2014 Having linked to "edituser.php?id=1" passing the id of the selected user, why would you then run a query to get the ids of all the users again? Get the details of the selected user for editing (ie. change password, set a flag to ban them etc.) Because i wanted - change password - ban user e.t.c to be links for example <a href='changepwd.php'> Change Password </a> if i was to click this while browsing editUser.php?id=1 , The user would not longer be selected Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted December 5, 2014 Author Share Posted December 5, 2014 If i am not making sense please tell me and i will try to explain what i mean. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 5, 2014 Share Posted December 5, 2014 The problem is you are not making sense of what we are telling you. Psycho already told you what you need to do here Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted December 5, 2014 Solution Share Posted December 5, 2014 Perhaps this in euser.php $sql = "SELECT id, username FROM $tbl_name ORDER BY username"; $result = $con->query($sql); echo "<table cellpadding='5'>"; while ($row = $result->fetch_assoc()) { echo "<tr><td>{$row['username']}</td> <td><a href='editUser.php?id={$row['id']}'>Edit User</a></td> <td><a href='changepassword.php?id={$row['id']}'>Change Password</a></td> <td><a href='banUser.php?id={$row['id']}'>Ban User</a></td> </tr>\n"; } echo "</table>\n"; 1 Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted December 5, 2014 Author Share Posted December 5, 2014 Perhaps this in euser.php $sql = "SELECT id, username FROM $tbl_name ORDER BY username"; $result = $con->query($sql); echo "<table cellpadding='5'>"; while ($row = $result->fetch_assoc()) { echo "<tr><td>{$row['username']}</td> <td><a href='editUser.php?id={$row['id']}'>Edit User</a></td> <td><a href='changepassword.php?id={$row['id']}'>Change Password</a></td> <td><a href='banUser.php?id={$row['id']}'>Ban User</a></td> </tr>\n"; } echo "</table>\n"; Thanks so much! 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.