查询返回数组而不是值

时间:2012-06-01 05:53:12

标签: php mysql

select query返回一个'array'而不是value.Because因为insert语句引发了错误。

这是我的保存方法,我获取id的值并在insert语句中使用该id

    function save() 
            {
              if(isset( $_POST['description']) && isset( $_POST['age']) && isset( $_POST['country']) && isset( $_POST['state'])) {
               $descrip = $_POST['description'];
               $ag = $_POST['age'];
               $country = $_POST['country'];
               $state= $_POST['state'];
            }
              $id = $this->db->query("SELECT table_tbldescription.Id  FROM table_tbldescription Left join table_tblpricetype1 as a on a.Id=table_tbldescription.Id  where table_tbldescription.Description = '". $descrip. "'");
              $arr = $id->result();
              //$arra = $sql->result();
              if(!empty($arr)) {
               $sql =  $this->db->query("Insert into table_tblpricetype1  (Id,age,country ,state) VALUES( '". $arr. "' ,'". $age. "' , '". $country. "','". $state. "')");
               }
               else{
               return false;
              }
         }

1 个答案:

答案 0 :(得分:0)

尝试使用:

$arr = $id->result()[0];