<?php
$p='Infos Updated';
$db=mysql_pconnect("localhost:3306","admin","admin");
mysql_select_db("product");
if (isset($_POST['update_button'])) {
if(isset($_POST['update'])){
$query1 = "UPDATE product SET status=1 WHERE status=0 and id in(". implode(',',
$_POST['update']).")";
$query2 = "UPDATE product SET status=0 WHERE status=1 and id not in(". implode(',',
$_POST['update']).")";
if(!mysql_query($query1)){
echo '<p>Error Updating '.mysql_error().'</p>';
}
if(!mysql_query($query2)){
echo '<p>Error Updating '.mysql_error().'</p>';
}
}
else{
if(!mysql_query("UPDATE product SET status=0")){
echo '<p>Error Updating '.mysql_error().'</p>';
}
}
}
$query= "SELECT * FROM product order by type,-seq DESC" ;
// get the rows and put them in an array
$result=mysql_query($query);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
?>
<table bgcolor='#AAccff' border="0" width='100%'
<tr>
<td id='td' width='15%'>Prod_id</td>
<td id='td' width='30%'>Category</td>
<td id='td' width='34%'>product</td>
<td id='td' width='15%'>Type</td>
<td id='td' width='6%'>Status</td></tr></table>
<?php
if (mysql_num_rows($result) == 0) {
echo "No rows found";
exit;
}
$myArray=array();
while ($row = mysql_fetch_assoc($result)){
$myArray[]=$row;}
?>
<form action="<?php $_SERVER['PHP_SELF']?>" method="POST">
<table bgcolor='#AAccAA' border="0" width='100%'>
<?php foreach ($myArray as $values): ?>
<tr>
<td width='15%'><?= $values['prod_id']?></td>
<td width='30%'><?= $values['cat_id']?></td>
<td width='34%'><?= $values['product']?></td>
<td width='15%'><?= $values['type']?></td>
<td><input type="checkbox" id="update_<?php echo $values['id']?>" name="update[]" value="<?php
echo $values['id']?>" <?php echo $values['status']==1 ? 'checked' : '' ?>"></td>
</tr>
</tr>
<?php endforeach; ?>
</table>
<input type="submit" value="Update" name="update_button">
</form>
</body>
</html>
|