เอา function insert update delete มาฝากคับ
/*
วิธีใช้
$data = array(
$Table_Member.'_firtname'=>$_POST['firstname'],
$Table_Member.'_lastname'=>$_POST['lastname'],
$Table_Member.'_nicname'=>$_POST['nicname']
);
$sql = insert_db($Table_Member, $data);
mysql_query($sql);
*/
function insert_db($nameTable, $data){
while($element = each($data)){
$insert[$element["key"]]="'".$element["value"]."'";
}
return $sql = "INSERT INTO `".$nameTable."` (".implode(",",array_keys($insert)).") VALUES (".implode(",",array_values($insert)).")";
}
/*
วิธีใช้
$data = array(
$Table_Member.'_firtname'=>$_POST['firstname'],
$Table_Member.'_lastname'=>$_POST['lastname'],
$Table_Member.'_nicname'=>$_POST['nicname']
);
$sql = update_db($Table_Member, array($Table_Member.'_id='=>$_POST['fid']), $data);
mysql_query($sql);
*/
function update_db($nameTable, $where, $data){
while($element = each($data)){
$update[$element["key"]]="`".$element["key"]."`='".$element["value"]."'";
}
while($element2 = each($where)){
$where[$element2["key"]]=$element2["key"]."'".$element2["value"]."'";
}
return $sql = "UPDATE `".$nameTable."` SET ".implode(",",$update)." WHERE ".implode(",",$where);
}
/*
วิธีใช้
$sql = delete_db($Table_Member, array($Table_Member.'_id='=>$_GET['id']));
mysql_query($sql);
*/
function delete_db($nameTable, $where){
while($element = each($where)){
$where[$element["key"]]=$element["key"]."'".$element["value"]."'";
}
return $sql = "DELETE FROM ".$nameTable." WHERE ".implode(",",$where);
}
วิธีใช้
$data = array(
$Table_Member.'_firtname'=>$_POST['firstname'],
$Table_Member.'_lastname'=>$_POST['lastname'],
$Table_Member.'_nicname'=>$_POST['nicname']
);
$sql = insert_db($Table_Member, $data);
mysql_query($sql);
*/
function insert_db($nameTable, $data){
while($element = each($data)){
$insert[$element["key"]]="'".$element["value"]."'";
}
return $sql = "INSERT INTO `".$nameTable."` (".implode(",",array_keys($insert)).") VALUES (".implode(",",array_values($insert)).")";
}
/*
วิธีใช้
$data = array(
$Table_Member.'_firtname'=>$_POST['firstname'],
$Table_Member.'_lastname'=>$_POST['lastname'],
$Table_Member.'_nicname'=>$_POST['nicname']
);
$sql = update_db($Table_Member, array($Table_Member.'_id='=>$_POST['fid']), $data);
mysql_query($sql);
*/
function update_db($nameTable, $where, $data){
while($element = each($data)){
$update[$element["key"]]="`".$element["key"]."`='".$element["value"]."'";
}
while($element2 = each($where)){
$where[$element2["key"]]=$element2["key"]."'".$element2["value"]."'";
}
return $sql = "UPDATE `".$nameTable."` SET ".implode(",",$update)." WHERE ".implode(",",$where);
}
/*
วิธีใช้
$sql = delete_db($Table_Member, array($Table_Member.'_id='=>$_GET['id']));
mysql_query($sql);
*/
function delete_db($nameTable, $where){
while($element = each($where)){
$where[$element["key"]]=$element["key"]."'".$element["value"]."'";
}
return $sql = "DELETE FROM ".$nameTable." WHERE ".implode(",",$where);
}