shir.zakhmi
Member

PHP:
<?php session_start();
if (isset( $_SESSION['login'])){
$Tablename = "news2";
$database = "news";
$location = "localhost";
$username = "root";
$password = "";
$conn=mysql_connect($location , $username , $password);
mysql_select_db($database);
if (isset($_GET['id'])){
$id=$_GET['id'];
$sql="delete from $Tablename where id = $id ";
if (mysql_query($sql)){
print "delete succesfully <br>";
}
else{
print "not delete";
}
}
$sql = "SELECT * FROM $Tablename";
$result = mysql_query($sql);
?>
<form action="<?php print $_SERVER['PHP_SELF'] ?>" method="POST">
<input type="submit" name="button" value="save">
<?php
print '<table border = "1">';
while($row = mysql_fetch_array($result))
{
if ($row['display'] == 1) {
$check = 'checked';
}
else{
$check = 'unchecked' ;
}
echo "<tr>
<td>" . $row['title'] . "</td>
<td>" . date(' Y h:i:s A',$row ['date2']) . "</td>
<td> <a href ='./edit&delete.php?id=$row[id]'><img border='0' src='./b_drop.png' width=100%></a></td>
<td><Input type = 'Checkbox' Name ='display[$row[id]]' $check></td>
<td><a href ='./editnews2.php?id=$row[id]'><img border='0' src='./b_edit.png' width='20' height='10'></a></td>";
print "</tr>";
}
print "</table>";
?>
</form>
<?php
$sql="UPDATE $Tablename SET display='1' WHERE " ;
$i = 1 ;
foreach ($_POST['display'] as $key=>$value){
$i ++;
if ($i <= count($_POST['display']) ){
$sql.=" id = ".$key ." or " ;
}
else
$sql.=" id = ".$key;
}
print $sql;
if (mysql_query($sql)){
print "succesfully";
}
else{
print "no update";
}
mysql_close($conn);
?>
<?php }?>
<a href="./index.php"> <h4>main</h4></a>