mam oto taki problem:
skrypty poniżej ( pochodzący z http://designconcept.webdev20.pl/articles/...-edycji-danych/ ) wyświetlają po drobnych przeróbkach z mojej bazy status użytkownika czyli 1 albo 0-odpowiednio aktywny,nieaktywny.Jako że nie znam się w ogóle na js proszę o pomoc w przerobieniu tego tak aby były dwa przyciski aktywuj i deaktywuj(w zależności który potrzebny) i po kliknięciu ich podmieniało wartość w bazie na przeciwną czyli z 1 na 0 i odwrotnie.Bardzo serdecznie proszę o pomoc.pozdrawiam
index.php
<body> <?php if($select_db) { } else { } $query = "SELECT * FROM user"; { } { $out[]=$row; } echo '<table id="tab"> <tr><th>Id</th><th>Stasus</th><th>Treść</th><th>Akcje</th></tr>'; foreach($out as $art) { if($art['status']==1){ }else { } //echo '<td>'.htmlspecialchars($art['status'],ENT_QUOTES).'</td>'; // echo '<td>'.htmlspecialchars($art['tresc'],ENT_QUOTES).'</td>'; echo '<td><form method="post"><input type="hidden" name="id" value="'.$art['id'].'" /><input class="sub" type="submit" value="Edytuj" /></form> <form method="post" action=""><input type="hidden" name="id" value="'.$art['id'].'" /><input class="del" type="submit" value="" title="Usuń" /></form></td>'; } echo '</table> <form action="" method="post" id="add_form"> <label>Tytuł:</label><input type="text" name="tytul" value="" /><br /> <label>Treść:</label><input type="text" name="tresc" value="" /><br /> <input class="sub2" type="submit" value="Dodaj" /> </form>'; ?> </body>
edit.php
<?php { if($select_db) { } else { } //$tresc = mysql_real_escape_string($_POST['tresc']); $query = "UPDATE user SET status = '$tytul'"; } ?>
custom.js
$(document).ready(function() { $('input.sub').live('click',function(){ var id_art = $(this).parent().find('input[type=hidden]').val(); var title = $(this).parent().parent().parent().find('td:eq(1)').text(); // var content = $(this).parent().parent().parent().find('td:eq(2)').text(); var a = $('<div/>', { class: 'box', html: '<form action="" method="post"><input type="hidden" name="id" value="'+id_art+'" /><label>Tytuł:</label><input type="text" name="status" value="'+title+'" /><br /><label>Treść:</label><input type="text" name="tresc" value="'+content+'" /><br /><input class="sub2" type="submit" value="Edytuj" /></form>' }); var thi = $(this).parent(); $(this).parent().parent().append(a); $(this).parent().remove(); a.find('form').submit(function(){ tr = a.parent().parent(); tr.find('td:eq(1)').text(dane['status']).css('background-color', 'yellow').animate({ opacity: 1 }, 3000, function() { $(this).css({'background-color' : '#DFF7FF', 'opacity' : '1'}); }); /* tr.find('td:eq(2)').text(dane['tresc']).css('background-color', 'yellow').animate({ opacity: 1 }, 3000, function() { $(this).css({'background-color' : '#DFF7FF', 'opacity' : '1'}); }); */ a.remove(); next_thi.before(thi); }); return false; }); return false; }); });
dwa buttony aktywuj albo dezaktywuj zrobię w php w pliku index.php
if($art['status']==1){ echo '<td><form method="post"><input type="hidden" name="id" value="'.$art['id'].'" /><input class="sub" type="submit" value="Dezaktywuj" /></form> <form method="post" action=""><input type="hidden" name="id" value="'.$art['id'].'" /><input class="del" type="submit" value="" title="Usuń" /></form></td>'; } else if(($art['status']==0)) { echo '<td><form method="post"><input type="hidden" name="id" value="'.$art['id'].'" /><input class="sub" type="submit" value="Aktywuj" /></form> <form method="post" action=""><input type="hidden" name="id" value="'.$art['id'].'" /><input class="del" type="submit" value="" title="Usuń" /></form></td>'; }
ale gdzie zrobić zamianę z 0 na 1 i odwrotnie i jak wysłać np później tą wartość do bazy z js.?tzn w js. bo chyba tam to trzeba zrobic zamienić 0 na 1 wysłać do edit.php i wysłać do bazy ?!tylko jak?