• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Select query with else

#1
Hello,
I have a few questions and hope you can help me there.
In my old version I made such a query.

PHP Code:
           $sql "SELECT
                        tb_kunde_id
                    FROM
                        db_kunde
                    WHERE
                        tb_kunde_vorname = :vorname
                            AND
                                tb_kunde_nachname = :nachname
                            AND
                                tb_kunde_land = :land"
;
 
           $select $db->prepare($sql);
 
           $select->bindParam(':vorname'$tb_kunde_vorname);
 
           $select->bindParam(':nachname'$tb_kunde_nachname);
 
           $select->execute();
 
           if($select->rowCount() < 1)
 
               {
 
                   $client_data['tb_kunde_vorname'] = $tb_kunde_vorname;
 
                   $client_data['tb_kunde_nachname'] = $tb_kunde_nachname;
 
                   $add_client $db->insert("db_kunde",$client_data) OR die("Error: ".$db->error()."</br> Zeile ".__LINE__);
 
                   $id_kunde $db->lastInsertId();
 
               }
 
           else
                
{
 
                   $results $select->fetch(PDO::FETCH_NUM);
 
                   $id_kunde $results[0];
 
               

Now I wonder how I need to query this in ELSE?
Reply

#2
In CodeIgniter Query Builder style:

PHP Code:
$this->db
->select('tb_kunde_id')
->
from('db_kunde')
->
where('tb_kunde_vorname',$tb_kunde_vorname)
->
where('tb_kunde_nachname'$tb_kunde_nachname)
->
where('tb_kunde_land'$tb_kunde_land);

$query $this->db->get();

if (
$query->num_rows() == 0) {
  $this->db->insert('db_kunde',$client_data);
  $id_kunde $this->db->insert_id();
}
else {
  $id_kunde $query->row()->tb_kunde_id;

Reply

#3
thanks
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.