Jump to content
Robert1995

PHP Create SQL Update script

Recommended Posts

Posted

Cadou poate va foloseste , l-am editat dintr-un cod existent poate au aparut ceva greseli nu stiu .

db_query credca se intelege ce face .



function update_entry($entry_id , $data = array()) {
unset($data['id']);// Prevent Mistakes

$data = array_map('mysql_escape_string', $data);
$data = wrap_my_array($data);

$sql = 'UPDATE {table_name} SET ';
$sql .= array_implode("=" , "," , $data);
$sql.= ' WHERE id = %s';
$query = db_query($sql , $entry_id);
}

function wrap_my_array($array , $wrapper = '"') {
$new_array = array();
foreach($array as $k=>$element){
if(!is_array($element)){
$new_array[$k] = $wrapper . $element . $wrapper;
}
}
return $new_array;

}

function array_implode( $glue, $separator, $array ) {
if ( ! is_array( $array ) ) return $array;
$string = array();
foreach ( $array as $key => $val ) {
if ( is_array( $val ) )
$val = implode( ',', $val );
$string[] = "{$key}{$glue}{$val}";

}
return implode( $separator, $string );
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...