Jump to content

[SOLVED] Need help formatting an echoed MySQL column with XHTML


lilwing

Recommended Posts

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?

<?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>");
?>

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.

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.