How to update all re-sortable values of a form in a database
Posted: Tue Nov 25, 2008 9:11 am
I have a list of entries of posts that will appear on the homepage,

detailed:

The Remove link works okay. The problem is with the ReSort link. I don't know how to get each textarea, it's ID and submit them one by one in the DB.
The user is supposed to be able to use the textareas and then push the ReSort link to update the entries in the database to appear in the new order.
This is the above form,
how can I get and update/re-sort all the entries of the form regardless of their current sorting?

detailed:

The Remove link works okay. The problem is with the ReSort link. I don't know how to get each textarea, it's ID and submit them one by one in the DB.
The user is supposed to be able to use the textareas and then push the ReSort link to update the entries in the database to appear in the new order.
This is the above form,
Code: Select all
<?php
$checkvalue=0;
$query = "SELECT
*
FROM
articles
WHERE
article_showhome=1
AND
(
article_expirehome=0
OR
(
article_expire_date>CURDATE() OR article_expire_date=CURDATE()
AND
article_expire_time>CURTIME() OR article_expire_time=CURTIME()
)
)
ORDER BY
article_importance ASC
LIMIT
10";
$result = mysql_query($query) or die('Error in Query: ' . mysql_error());
echo "<form id='item' name='item' method='post' action='index.php?section=articles&action=resorthomepage'> <table width='750' border='0' cellpadding='2' cellspacing='2' style='text-indent:4px;'>
<tr>
<td height='12' align='center' valign='middle'>Order</td>
<td align='left' valign='middle'>Title</td>
<td align='left' valign='middle'>Publish Date </td>
<td align='left' valign='middle'>Expiry Date </td>
<td align='left' valign='middle'>Options </td>
</tr>";
while($row = mysql_fetch_array($result)){
$get_id=$row['article_id'];
$get_title=$row['article_title'];
$get_content=$row['article_content'];
$get_date=$row['article_publish_date'];
$get_time=$row['article_publish_time'];
$get_tags=$row['article_tags'];
$get_shownews=$row['article_shownews'];
$get_previewimage=$row['article_previewimage'];
$get_contentimage=$row['article_contentimage'];
$get_redirect=$row['article_redirect'];
$get_showhome=$row['article_showhome'];
$get_expirehome=$row['article_expirehome'];
$get_showrss=$row['article_showrss'];
$get_importance=$row['article_importance'];
$get_expire_date=$row['article_expire_date'];
$get_expire_time=$row['article_expire_time'];
$checkvalue=$checkvalue+1;
echo "
<tr onMouseOver='this.style.backgroundColor=\"#F3FE76\"' onMouseOut='this.style.backgroundColor=\"transparent\"'>
<td width='51' height='26' align='center' valign='middle'><input name='ordervalue$checkvalue' type='text' value='$get_importance' size='4' maxlength='2' /></td>
<td width='288' align='left' valign='middle'>$get_title</td>
<td width='233' align='left' valign='middle'>$get_date - $get_time</td>
<td width='233' align='left' valign='middle'>";
if ($get_expirehome==0){echo "Never";}else{ echo"$get_expire_date - $get_expire_time";}
echo "<td width='230' align='left' valign='middle'><img src='files/images/layout/delete.png' alt='remove' /><a href='index.php?section=articles&action=removehomepage&id=$get_id'>Remove</a>
<input style='display:none;' type='hidden' name='itemid' value='$get_id' /></td>
</td>
</tr>";
}
//end of entry table
echo "
</table><br/>
<div align='left' style='text-indent:8px;'><img src='files/images/layout/refresh.png' alt='resort' /><a href='javascript:document.item.submit();'> ReSort</a></div>
</form>
<br/><img src='files/images/layout/separator.png' alt='separator' />
";
//end of entry list
?>