Проверьте информацию двойной стол

Я предпочел бы сделать разные таблицы для детей и родителей примерно такими.

Таблица для родителей

parent_id     name            
1             Roberto         
2             Maria           
3             Mary     

Таблица для детей

children_id  parent_id  name
1            1          Michael     
2            1          Dia 
3            2          John

.... и т. д.

0
задан Pedro HB 5 March 2019 в 05:29
поделиться

1 ответ

Проверьте имя в БД перед вставкой новой записи

$data = array(
    "id_username" => $this->session->id_account,
    "name_character" => $nome,
    "birthdate" => $data,
    "origin" => $origem,
    "gender" => $sexo,
    "pergunta1" => $pergunta3,
    "pergunta2" => $pergunta4,
    "history" => $history
);
$if_exists = $this->usuarios_model->check_user($data['name_character']);

//Here apply condition to check if user is exists or not
if($if_exists > 0){
    //Already Exists
}else{
    $this->usuarios_model->criarPersonagem($data); //New registration
}

Модель

public function check_user($name_character){

    //Here, get the number if rows with the new user name
    return $this->db->get_where('characters', ['Character' => $name_character])->num_rows();
}
0
ответ дан Danish Ali 5 March 2019 в 05:29
поделиться
Другие вопросы по тегам:

Похожие вопросы: