php - Disable delete button if record exist in multiple table -


i have here mysql records display in html table delete button. need disable delete button if record exist in both database table.

how can disable delete button per row if record exist in both table? appreciate.

$search = $mysqli1->real_escape_string($_post['bid']); $search = preg_replace("/[^a-za-z0-9 ]/", '', $search); $search = $_post['bid']; $res = $mysqli1->query("select * code item '%$search%' or item_code '%$search%' or cat_code '%$search%' order item_code asc");  while($r = $res->fetch_assoc()){ echo "<tr> <td><a href='#' id='".$r['id']."' class='del'><img src='../images/del.png'></a></td> </tr>"; } 

throw in simple if() statement connected both queries in pdo use ->rowcount() not sure in mysqli

so logic you'd need

query1 = counted rows in table1

query2 = counted rows in table2

as if said if exists in both tables should hide you're going work if-or statement

if(query1 == 0 || query2 == 0){  //show button } 

what here stands simple:

if(query1 equals 0 rows or query2 equals 0 rows){  //show button } //while don't put else else won't show //so if there value of 1+ rows in both query1 , query2 won't show 

if want me provide pdo example reply

edit:

pdo class make easier connect

class database extends pdo {     private $db;     public function database($host, $user, $pass, $db) {         try {             $this->db = new pdo("mysql:dbname=".$db.";host=".$host.";",    $user, $pass);                } catch(pdoexception $e) {             die('an error has occurred! [code: '.$e->getcode().']!  <br/>more info: ['.$e->getmessage().']!');         }     }     public function runquery($query) {         try{             return $this->db->query($query);         } catch(pdoexception $e) {             die('an error has occurred! [code: '.$e->getcode().']!<br/>more info: ['.$e->getmessage().']!');         }            } } 

now row counting: updated there little mistake && , 2x query1 check

 $consite = new database('dbhost','dbusername','dbpassword','dbname');  $query1 = $consite->runquery("select * table1");  $query2 = $consite->runquery("select * table2");  if($query1->rowcount() == 0 || $query2->rowcount() == 0) {   //do while statement loop through   //if done while statement shows delete button   //for items not in both tables  } 

sorry lazy add while statement ;) if correct can check multiple tables in sql query can 1 query if make multi check following 1 query!

edit: logical steps question:

1) connect database

2) make query table1

3) count entries(records) table1

4) make query table2

5) count entries(records) table2

6) check if one of them equals 0

7) if one of them equals 0 entries (records(rows)) show button


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -