php code to rearrange row order in database on update of selected row -
tablename: news
column:
headline, send_sub_top, sub_top_priority.
below table structure in database.
i need when update selected row form. updates send_sub_top = "inactive"
in database , rearrange order of sub_top_priority
column in database.
for example:
if delete row 3 in database update send_sub_top = "inactive"
of row 3 , sub_top_priority = 0
of row 3 , rearrange order of sub_top_priority
column in ascending
order 1,2,3,4.
i create code update send_sub_top column = inactive
in database not rearrange sub_top_priority
order...
my code example -- code update send_sub_top = inactive
, keep sub_top_priority
column order like...
after deleting 3rd row 1,2,4,5. need 1,2,3,4.
id headline send_sub_top sub_top_priority 1 active 1 2 test active 2 3 nice active 3 4 great active 4 5 demo active 5
plz me....thanks in advance..
below code...
<?php foreach($sub_top_select $sub_top) { ?> <li><a href="javascript:return(0);" remove_sub_top_news="<?php echo $sub_top['id']; ?>"> <img src="img/error.png" height="14px" width="14px" /></a></li> <?php } ?>
php code update inactive in database...
but need rearrange order of sub_top_priority
column in ascending
order 1,2,3,4.
<?php if(isset($_post['remove_sub_top_news'])) { $id = mysql_real_escape_string(trim(htmlspecialchars($_post['remove_sub_top_news']))); $sql = "select id,send_sub_top news id='$id'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); mysql_query("update news set send_sub_top='inactive' id=".mysql_real_escape_string(trim(htmlspecialchars($_post['remove_sub_top_news'])))); if(mysql_affected_rows() > 0) { $_session['message'] = "news removed subtop successfully"; header("location:sethomepage.php"); exit; } } ?>
first update send_sub_top
value.
then select data table condition set_sub_top
= 'active' , order sub_top_priority
ascending.
then looping whole data of select query update sub_top_priority
increment of 1.
nb : method if there not data in table.
Comments
Post a Comment