• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi Table Select (Active Records)

#1
I am trying to check multiple databases with user given string. But SQL query always returns true. It must return false, if phone number exist in individual or corporate databases.

Individual Users Database:

Code:
| id |     name     |     phone       |     gender     |
--------------------------------------------------------
| 1  |     John     |     5551928321  |     male       |
| 2  |     Michael  |     5553270543  |     male       |

Corporate Users Database:

Code:
| id |     name     |     phone       |     company    |
--------------------------------------------------------
| 1  |     Megan    |     5553748594  |     demo1      |
| 2  |     Ethan    |     5559182012  |     demo2      |

PHP:

PHP Code:
$phone '5551928321'// $this->input->post('phone', true);
$query $this->db->select('individual.id, corporate.id')
->
where('individual.phone'$phone)
->
or_where('corporate.phone'$phone)
->
get('individual, corporate');

if (
$query->num_rows() > 0) echo 'FALSE';
else echo 
'TRUE'

I will be very pleased if someone light me up for see how it will be work.

Thank you so much.
Reply

#2
Why did you save data in different databases? You can create a single database with two tables. One for "Individual Users" and other for "Corporate Users ". then you do a join. Sorry for my poor english Big Grin
Reply

#3
You have to use the database names for your tables like db1.individual and db2.corporate
And you have to connect to both of course Wink

Reply

#4
A model's method (returns boolean) that includes two separate queries?
Reply

#5
Assuming you meant different tables, not different databases...

Have you tried to debug by using the profiler  $this->output->enable_profiler(TRUE) or sending $this->db->last_query() to the log?

Does the query shown by one of the above commands work if you run it manually at the command line or in something like PhpMyAdmin?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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