A Better Way?
Posted: Tue Feb 06, 2007 3:26 pm
I'm writing blog software and was working on a way to change the status of an article to determine where it is filed. My code works and works well but it seems like there might have been an easier way to achieve the second part. Any ideas?
The last section of code is repeat two more times for the different categories (Current and Archive).
So when I change the status via the select menu, it changes the status in the db and moves the article to the appropriate category on this page.
Thanks,
-Pete
Code: Select all
if (isset($_POST['update_incomplete'])){
$query = "UPDATE article SET status='$_POST[status]'";
mysql_query($query) or die (mysql_error());
header ("location: $_SERVER[PHP_SELF]");
}Code: Select all
echo "<ul>";
echo '<form method="POST">';
$query = "SELECT * FROM article WHERE status=1";
$result = mysql_query($query) or die (mysql_error());
while($row=mysql_fetch_assoc($result)){
echo "<li><a href=\"article.php?$a_id\">$row[title]</a><br />";
echo 'Status: ';
switch ($row['status']) {
case 0:
echo '<select name="status"><option value="0" selected="selected">Incomplete</option><option value="1">Current</option><option value="2">Archive</option></select>';
break;
case 1:
echo '<select name="status"><option value="0">Incomplete</option><option value="1" selected="selected">Current</option><option value="2">Archive</option></select>';
break;
case 2:
echo '<select name="status"><option value="0">Incomplete</option><option value="1">Current</option><option value="2" selected="selected">Archive</option></select>';
break;
}
echo "</li>";
}
echo "</ul>";
.....more code
.....submit buttonSo when I change the status via the select menu, it changes the status in the db and moves the article to the appropriate category on this page.
Thanks,
-Pete