[ PHP ] Function INSERT simple Array with dynamic Table and Field to Php-Mysql , Add data dynamically to an Array

http://jumnuoy.blogspot.com/2013/06/function-insert-simple-array-with.htmlhow y can store in my BD Mysql this array:
$data = array(
"id" => "1",
"title" => "This my test",
"by"=>"Socheat"
);
ID |  TITLE       |  BY
---------------------------
1 This my test1 SOCHEAT
9 This my test1 SARET

Ok, let to go:

/*Table name*/

$table = "title";

/*Data array to insert*/
$data = array(
"id" => "1",
"title" => "This my test",
"by"=>"Socheat"
);

insert($table, $data);

-Function for insert:
function insert($table, $data)
{
$keys = array();
$values = array();
foreach($data as $key => $value)
{
$keys[] = $key;
$values[] = $value;
}
$check = mysql_query("INSERT INTO $table (".implode(',',$keys).") VALUES('" . implode("', '", $values) . "')");
}

how y can store in my BD Mysql this array:
$data = array(
"id" => "1",
"title" => "This my test",
"by"=>"Socheat"
);
ID |  TITLE       |  BY
---------------------------
1 This my test1 SOCHEAT
9 This my test1 SARET

Ok, let to go:

/*Table name*/

$table = "title";

/*Data array to insert*/
$data = array(
"id" => "1",
"title" => "This my test",
"by"=>"Socheat"
);

insert($table, $data);

-Function for insert:
function insert($table, $data)
{
$keys = array();
$values = array();
foreach($data as $key => $value)
{
$keys[] = $key;
$values[] = $value;
}
$check = mysql_query("INSERT INTO $table (".implode(',',$keys).") VALUES('" . implode("', '", $values) . "')");
}

0 comments:

Post a Comment

Followers

រឿង ដែលខានមើលមិនបាន

Contact us

Name

Email *

Message *

Your Language

Online

Copyright 2009 Simplex Celebs All rights reserved Designed by www.sruol9.com