rajesh007king
07-24-2012, 04:34 PM
hi i have a table with 3 fields. Airlines service, Id and Blacklist(0 or 1). when i fetch the data from the table i ll get the name of the airline service and there blacklist status as checked if the value is 1 and unchecked if the value is 0. after fetching the results if i make any changes and submit the changes i need to update my database accordingly. i am using mvc architecture in my website. can any one help me....
thanks in advance.
Blacklist.Phtml:
<?php
//require('template/adminheader.phtml')?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h1>Blacklist</h1>
<ul></ul>
<table class="table" border="2" cellspacing="5" cellpadding="5">
<thead>
<tr>
<th>Checked</th>
</tr>
</thead>
<td><?php foreach ($view->peopleList as $person):?></td>
<tr>
<td><input id="$person->getBlacklist()"value="<?php $person->getID(); ?>" name="Airlines[]" type="checkbox" <? if ($person->getBlacklist()==="1") echo "checked=checked"; ?> class="span2">
<?php echo $person->getService_Name();?> </input> </td>
</tr>
<?php endforeach; ?>
</table>
</ul>
</table>
<button name="submit" type="submit" class="btn btn-large">S</button>
</form>
Blacklist.php
<?php
$view->pageTitle = 'Database';
require_once('Models/class.logintable.php');
require_once('Models/class.rulesdef.php');
$PNR=$_GET['PNR'];
$database1 = new rulesdef();
$view->peopleList = $database1->Blacklist();
//$view1->peopleList = $database1->ischecked();
if(isset($_POST['submit']))
{
if($view->err=='')
{
$view->laptops=array();
$dbupdate=new logintable();
$dbupdate->updateitemsdetails1($_POST);
//$view->laptops=$dbupdate->getDetails();
}
}
require_once('Views/Blacklist.phtml');
logintable.php
public function updateitemsdetails1($data)
{
foreach ($_POST['Airlines'] as $value)
{
print_r($_POST['Airlines[]']);
//print_r($ids);
// if(isset ($_POST['Airlines']))
// {
//
// $n=$_POST['id'];
// $va='1';
// $sql="UPDATE Rules SET Blacklist='$va' WHERE Service_Name='British Airlines'";
// $results=$this->dbh->prepare($sql);
// $results->execute(array());
// }
// else
// {
// $va='0';
// $sql="UPDATE Rules SET Blacklist='$va' WHERE Service_Name='Brussils'";
// $results=$this->dbh->prepare($sql);
// $results->execute(array());
//
// }
// elseif(!isset ($_POST['Airlines']))
// {
//
// //alert("king");
// $va='1';
// $sn=$_POST['Airlines'];
//
// $sql="UPDATE Rules SET Blacklist='0' WHERE Service_Name='Brussils";
// $results=$this->dbh->prepare($sql);
// $results->execute(array());
//
// }
}
}
rulesdef.php
<?Php
require_once 'Models/class.rules.php';
require_once 'Models/class.database.php';
class rulesdef
{
protected $dbh;
protected $db;
public function __construct() {
$this->db=Database::getInstance();
$this->dbh=$this->db->getDbh();
}
public function Blacklist()
{
$sql="select * from Rules order by ID ";
$results= $this->dbh->prepare($sql);
$results->execute();
$personArray=array();
while($row=$results->fetch())
{
$personArray[]=new Rules($row);
}
return $personArray;
print_r($_POST['Airlines[]']);
}
}
thanks in advance.
Blacklist.Phtml:
<?php
//require('template/adminheader.phtml')?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h1>Blacklist</h1>
<ul></ul>
<table class="table" border="2" cellspacing="5" cellpadding="5">
<thead>
<tr>
<th>Checked</th>
</tr>
</thead>
<td><?php foreach ($view->peopleList as $person):?></td>
<tr>
<td><input id="$person->getBlacklist()"value="<?php $person->getID(); ?>" name="Airlines[]" type="checkbox" <? if ($person->getBlacklist()==="1") echo "checked=checked"; ?> class="span2">
<?php echo $person->getService_Name();?> </input> </td>
</tr>
<?php endforeach; ?>
</table>
</ul>
</table>
<button name="submit" type="submit" class="btn btn-large">S</button>
</form>
Blacklist.php
<?php
$view->pageTitle = 'Database';
require_once('Models/class.logintable.php');
require_once('Models/class.rulesdef.php');
$PNR=$_GET['PNR'];
$database1 = new rulesdef();
$view->peopleList = $database1->Blacklist();
//$view1->peopleList = $database1->ischecked();
if(isset($_POST['submit']))
{
if($view->err=='')
{
$view->laptops=array();
$dbupdate=new logintable();
$dbupdate->updateitemsdetails1($_POST);
//$view->laptops=$dbupdate->getDetails();
}
}
require_once('Views/Blacklist.phtml');
logintable.php
public function updateitemsdetails1($data)
{
foreach ($_POST['Airlines'] as $value)
{
print_r($_POST['Airlines[]']);
//print_r($ids);
// if(isset ($_POST['Airlines']))
// {
//
// $n=$_POST['id'];
// $va='1';
// $sql="UPDATE Rules SET Blacklist='$va' WHERE Service_Name='British Airlines'";
// $results=$this->dbh->prepare($sql);
// $results->execute(array());
// }
// else
// {
// $va='0';
// $sql="UPDATE Rules SET Blacklist='$va' WHERE Service_Name='Brussils'";
// $results=$this->dbh->prepare($sql);
// $results->execute(array());
//
// }
// elseif(!isset ($_POST['Airlines']))
// {
//
// //alert("king");
// $va='1';
// $sn=$_POST['Airlines'];
//
// $sql="UPDATE Rules SET Blacklist='0' WHERE Service_Name='Brussils";
// $results=$this->dbh->prepare($sql);
// $results->execute(array());
//
// }
}
}
rulesdef.php
<?Php
require_once 'Models/class.rules.php';
require_once 'Models/class.database.php';
class rulesdef
{
protected $dbh;
protected $db;
public function __construct() {
$this->db=Database::getInstance();
$this->dbh=$this->db->getDbh();
}
public function Blacklist()
{
$sql="select * from Rules order by ID ";
$results= $this->dbh->prepare($sql);
$results->execute();
$personArray=array();
while($row=$results->fetch())
{
$personArray[]=new Rules($row);
}
return $personArray;
print_r($_POST['Airlines[]']);
}
}