mysqli - How to search a word on two table if have or not by php query -
i want find out userid 2 table username username have stayed in table2 or not. means if username match in table query collect userid.
table 1: username --- userid > john --- 100 table 2: username --- userid > colin --- 101
i read many article here nut cannot understand should do.
now think: need john's uesrid,
so tried:
$username = "john"; $q = "select userid table1,table2 table1.username = '$username' or table2.username = '$username'"; $result = mysqli_query($this->connection, $q);
from understand want check if name exist in 1 of tables.
here easy php code:
<?php session_start(); include 'db_connect.php'; $check_1 = mysqli_query("select * table_1 username = '$username'"); $check_2 = mysqli_query("select * table_2 username = '$username'"); if(mysqli_num_rows($check_1)==0){ //didnt exist in table 1 } else if(mysqli_num_rows($check_2)==0){ //no result in table 2 either. } else{ //what want if username doesnt exist }
let me know how worked out :)
Comments
Post a Comment