0

I need to parse the following code and process the resulting data.

foreach($job as $x=>$x_value)
  {
  echo "Key=" . $x . ", Value=" . $x_value;
  echo "<br>";
  }

The above code is returning the following as expected.

Key=vca_id, Value=20130<br>Key=uuid, Value=3c87e0b3-cfa<br>Key=originate_time, Value=2013-03-15 14:30:18<br>

What I need to do is to put the values in mysql database. So the insert statement would look something like this...

insert into test.master_table (vca_id, uuid, originate_time) values ('20130', '3c87e0b3-cfa', '2013-03-15 14:30:18')

What is the correct way to save the array values to mysql database?

1

3 Answers 3

1
<?php 
mysql_query("insert into test.master_table(vca_id, uuid, originate_time)values('".$job['vca_id']."','".$job['uuid']."','".$job['originate_time']."')");
?>
Sign up to request clarification or add additional context in comments.

Comments

1

Well i will recommend implode

$keys = array();
$values = array();
foreach($job as $x => $x_value)
{
    $keys[] =   $x;
    $values[]   =   $x_value;
}

$query  =   'INSERT INTO test.master_table' . '('.implode(',',$keys) .') VALUES (' .implode(',',$values) . ')';

Comments

1

You can try this

$temp_value_arr = array();
$query = "INSERT into test.master_table SET ";
foreach($job as $x=>$x_value)
{
   $query .= "$x = '$x_value',";
}

$query = rtrim($query, ',');
mysql_query($query);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.