Insert data into a table from another 4

Asked

Viewed 35 times

0

I have this code to enter data into the database, I would like to insert data from 4 tables into one. But consecutively, I tried this way only that it adds the same data to the last 3 tables and only changes the data of the first select. Someone would know to help me?

$link = mysqli_connect('localhost','root','','teste2');
$link->set_charset("utf8");

$query = "SELECT * from review_store";
$select = mysqli_query($link, $query);

while($row = mysqli_fetch_array($select)){

$review_store= array(
$review_id_store = 'review_id_store'=>$row['review_id'],
$store_id_store = 'store_id_store'=>$row['store_id']//REVIEW_STORE
);


$queryx = "SELECT * from review_entity_summary";
$selectx = mysqli_query($link, $queryx);

$row = mysqli_fetch_array($selectx);

 $review_sumary= array(
$primary_id = 'primary_id'=>$row['primary_id'],
$entity_pk_value_summary = 'entity_pk_value_summary'=>$row['entity_pk_value'],
$entity_type = 'entity_type'=>$row['entity_type'],
$reviews_count = 'reviews_count'=>$row['reviews_count'],
$rating_summary = 'rating_summary'=>$row['rating_summary'],
$store_id_summary = 'store_id_summary'=>$row['store_id']//REVIEW_ENTITY_SUMMARY
);


$querys = "SELECT * from review_detail";
$selects = mysqli_query($link, $querys);


$row = mysqli_fetch_array($selects);

 $review_det= array(
$id = 'detail_id'=>$row['detail_id'],
$review_id = 'review_id_detail'=>$row['review_id'],
$store_id_detail = 'store_id_detail'=>$row['store_id'],
$title = 'title'=>$row['title'],
$detail = 'detail'=>$row['detail'],
$nickname = 'nickname'=>$row['nickname'],
$customer_id = 'customer_id'=>$row['customer_id']//REVIEW_DETAIL
);

$querya = "SELECT * from review";
$selecta = mysqli_query($link, $querya);

$row = mysqli_fetch_array($selecta);

$review = array(
$review_id = 'review_id'=>$row['review_id'],
$criadoem = 'criadoem'=>$row['created_at'],
$entity_id = 'entity_id'=>$row['entity_id'],
$entity_pk_value = 'entity_pk_value'=>$row['entity_pk_value'],
$status_id = 'status_id'=>$row['status_id']//REVIEW
);

print_r(array($review_store, $review_sumary, $review_det, $review)); 

$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$query = "INSERT INTO comentproduto (`primary_id`, `entity_pk_value_summary`, `entity_type`, `reviews_count`, `rating_summary`, `store_id_summary`, `review_id_store`, `store_id_store`, `detail_id`, `review_id_detail`, `store_id_detail`, `title`, `detail`, `nickname`, `customer_id`, `review_id`, `created_at`, `entity_id`, `entity_pk_value`, `status_id`) VALUES ('".$review_store[$review_id_store]."', '".$review_store[$store_id_store]."', '".$review_sumary[$primary_id]."', '".$review_sumary[$entity_pk_value_summary]."', '".$review_sumary[$entity_type]."', '".$review_sumary[$reviews_count]."', '".$review_sumary[$rating_summary]."', '".$review_sumary[$store_id_summary]."', '".$review_det['detail_id']."', '".$review_det[$review_id]."', '".$review_det[$store_id_detail]."', '".$review_det['title']."', '".$review_det['detail']."', '".$review_det['nickname']."', '".$review_det['customer_id']."', '".$review['review_id']."', '".$review['criadoem']."', '".$review['entity_id']."', '".$review['entity_pk_value']."', '".$review['status_id']."')";
$connection->query($query);
}

How you’re being saved

First "spin"

[0] => Array
    (
        [review_id_store] => 7 //SOMENTE ESSES VALOR É ALTERADO
        [store_id_store] => 0 //SOMENTE ESSES VALOR É ALTERADO
    )

[1] => Array
    (
        [primary_id] => 26
        [entity_pk_value_summary] => 1028
        [entity_type] => 1
        [reviews_count] => 1
        [rating_summary] => 100
        [store_id_summary] => 2
    )

[2] => Array
    (
        [detail_id] => 1
        [review_id_detail] => 1
        [store_id_detail] => 1
        [title] => Ótimo! 
        [detail] => Adorei o buquê, muito lindo! 
        [nickname] => Débora 
        [customer_id] => 94
    )

[3] => Array
    (
        [review_id] => 1
        [criadoem] => 2016-07-13 12:54:07
        [entity_id] => 1
        [entity_pk_value] => 1042
        [status_id] => 1
    )

)

Second "spin"

[0] => Array
    (
      [review_id_store] => 7 //SOMENTE ESSES VALOR É ALTERADO
      [store_id_store] => 1 //SOMENTE ESSES VALOR É ALTERADO
    )

[1] => Array
    (
      [primary_id] => 26
      [entity_pk_value_summary] => 1028
      [entity_type] => 1
      [reviews_count] => 1
      [rating_summary] => 100
      [store_id_summary] => 2
    )

[2] => Array
    (
      [detail_id] => 1
      [review_id_detail] => 1
      [store_id_detail] => 1
      [title] => Ótimo! 
      [detail] => Adorei o buquê, muito lindo! 
      [nickname] => Débora 
      [customer_id] => 94
    )

[3] => Array
    (
      [review_id] => 1
      [criadoem] => 2016-07-13 12:54:07
      [entity_id] => 1
      [entity_pk_value] => 1042
      [status_id] => 1
    )

  )

As you can see only the first values are changed, after they run all the data, each line (1470) it goes to the second, then it does not leave the null fields only that runs one at a time filling the initial values in the others.

  • You want to change the database by putting all data into a single table, and deleting the original 4?

  • No need to delete, just want to put the data of the 4 tables in other 4

  • A backup or something?

  • Voce wants to transfer the records that already exist in 4 tables to only one

  • @Guilhermecostamilam Yes, a backup only that instead of making 6 scripts that are actually 6 tables I would like to know if there is how I query them at once searching the values I would like

  • @Victor Exactly, let’s assume: Nome, Idade table Pessoa and catch the Peso, Altura table Corpo etc...

  • This I can, but I would have to do 1 by 1, I would like to make these selects in several tables at once

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.