PHPR Update Selected Record With Value Button

Category: Programming Written by Naldi Hits: 391

* Create table hr_statuses :

Create table statuses (
status VARCHAR(30) PRIMARY KEY
)


* Create Code Snippet in visual studio :

$str= "<select id='mycontrol'><option value=''>Select status</option>";

//select values from database
global $conn;
$strSQL = "select status from hr_statuses";
$rs = db_query($strSQL,$conn);
while ($data = db_fetch_array($rs))
  $str.="<option value='".$data["status"]."'>". $data["status"]."</option>";
$str.="</select>";
echo $str;


* Create button "Update Selected" :

#ClientBefore
// make sure user selected some value from dropdown box
if ($("#mycontrol").val()=="") { 
alert('Choose something already');
return false;
}
// send the selected value to OnServer event
params['status']=$("#mycontrol").val();

#OnServer
global $dal;
while ( $data = $button->getNextSelectedRecord() ) {
  $sql = "Update hr_timesheet set status='".$params['status']."' where timesheet_id=".$data["timesheet_id"];
   CustomQuery($sql);
}

#ClientAfter
location.reload();