lilwing Posted June 19, 2008 Share Posted June 19, 2008 Okay, say I am creating a user management area for the owner of the website, for example. In particular, I want to create a form that echoes all the usernames that exist in the users table, and then places checkboxes next to them, and then a submit button, that deletes the username. If I wanted to echo all the usernames on the database, I would do the following. mysql_connect('host','username','password'); mysql_select_db('dbname'); $query = mysql_query('SELECT username FROM users ORDER BY username ASC'); while($row = mysql_fetch_array($query)) { $list = $row['username']; echo $list; } What can I do to format the list using the XHTML ul and li tags, and assign checkboxes to each one? Link to comment https://forums.phpfreaks.com/topic/110860-solved-need-help-formatting-an-echoed-mysql-column-with-xhtml/ Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 <?php mysql_connect('host','username','password'); mysql_select_db('dbname'); echo('<form action="page.php" method="POST">'); echo("<ul>"); $query = mysql_query('SELECT username FROM users ORDER BY username ASC'); while($row = mysql_fetch_array($query)) { $list = $row['username']; echo("<li>"); echo('<input type="checkbox" name="username[]" value="'.$list.'" />'); echo("</li>"); } echo("</ul>"); echo("</form>"); ?> Link to comment https://forums.phpfreaks.com/topic/110860-solved-need-help-formatting-an-echoed-mysql-column-with-xhtml/#findComment-568802 Share on other sites More sharing options...
lilwing Posted June 19, 2008 Author Share Posted June 19, 2008 Thanks. I changed one thing, though: echo('<input type="checkbox" name="username[]" value="'.$list.'" />' . $list); That way, the username displays next to the checkbox. Link to comment https://forums.phpfreaks.com/topic/110860-solved-need-help-formatting-an-echoed-mysql-column-with-xhtml/#findComment-568808 Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 Ah yeah forgot about that part! xD Link to comment https://forums.phpfreaks.com/topic/110860-solved-need-help-formatting-an-echoed-mysql-column-with-xhtml/#findComment-568810 Share on other sites More sharing options...
lilwing Posted June 19, 2008 Author Share Posted June 19, 2008 Quick question: on the form action page, what would be the proper query to drop the selected records containing those usernames? I think something along the lines of: mysql_query('DROP RECORD FROM users WHERE username='$_POST['???']') or die(mysql_error()); I am not sure what to make the post variable, or if my SQL query is correct. Please let me know. Link to comment https://forums.phpfreaks.com/topic/110860-solved-need-help-formatting-an-echoed-mysql-column-with-xhtml/#findComment-568885 Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 <?php foreach ($_POST["username"] as $_key => $_value) { mysql_query("DELETE FROM users WHERE username='".$_value."'"); } ?> I think that should work, didn't test it though. Link to comment https://forums.phpfreaks.com/topic/110860-solved-need-help-formatting-an-echoed-mysql-column-with-xhtml/#findComment-568894 Share on other sites More sharing options...
lilwing Posted June 19, 2008 Author Share Posted June 19, 2008 Danke schön, Hr. Stephen! Link to comment https://forums.phpfreaks.com/topic/110860-solved-need-help-formatting-an-echoed-mysql-column-with-xhtml/#findComment-568902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.