Skip to main content
added 121 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

I have the following function that works fine, is. Is there a better way to do it and will this be efficient if iI have 100+ rows returned from each table?

The database

Tables

  • wcx_articleswcx_articles
  • wcx_videoswcx_videos
  • wcx_appswcx_apps
  • wcx_linkswcx_links

The corresponding _active column for each table

  • article_activearticle_active
  • video_activevideo_active
  • app_activeapp_active
  • link_activelink_active

_active_active is a switch 1 or 0

This is my current function

        public function findInactiveItems() {
        
    $query = "SELECT * FROM wcx_articles WHERE article_active = '0'
    UNION
    SELECT * FROM wcx_videos WHERE video_active = '0'
    UNION
    SELECT * FROM wcx_apps WHERE app_active = '0'
    UNION
    SELECT * FROM wcx_links WHERE link_active = '0'
    ";
        if( $this->num_rows( $query ) > 0 ) {    
            $count = $this->num_rows($query);
            return $count;
        }
    }

 public function num_rows( $query ) {
    $query = $this->link->query( $query );
    if( mysqli_error( $this->link ) ) {
        $this->log_db_errors( mysqli_error( $this->link ), $query, 'Fatal' );
        return mysqli_error( $this->link );
    }
    else {
        return mysqli_num_rows( $query );
    }
    mysqli_free_result( $query );
}

I have the following function that works fine, is there a better way to do it and will this be efficient if i have 100+ rows returned from each table?

The database

Tables

  • wcx_articles
  • wcx_videos
  • wcx_apps
  • wcx_links

The corresponding _active column for each table

  • article_active
  • video_active
  • app_active
  • link_active

_active is a switch 1 or 0

This is my current function

        public function findInactiveItems() {
        
    $query = "SELECT * FROM wcx_articles WHERE article_active = '0'
    UNION
    SELECT * FROM wcx_videos WHERE video_active = '0'
    UNION
    SELECT * FROM wcx_apps WHERE app_active = '0'
    UNION
    SELECT * FROM wcx_links WHERE link_active = '0'
    ";
        if( $this->num_rows( $query ) > 0 ) {   
            $count = $this->num_rows($query);
            return $count;
        }
    }

 public function num_rows( $query ) {
    $query = $this->link->query( $query );
    if( mysqli_error( $this->link ) ) {
        $this->log_db_errors( mysqli_error( $this->link ), $query, 'Fatal' );
        return mysqli_error( $this->link );
    }
    else {
        return mysqli_num_rows( $query );
    }
    mysqli_free_result( $query );
}

I have the following function that works fine. Is there a better way to do it and will this be efficient if I have 100+ rows returned from each table?

The database

Tables

  • wcx_articles
  • wcx_videos
  • wcx_apps
  • wcx_links

The corresponding _active column for each table

  • article_active
  • video_active
  • app_active
  • link_active

_active is a switch 1 or 0

This is my current function

public function findInactiveItems() {
        
    $query = "SELECT * FROM wcx_articles WHERE article_active = '0'
    UNION
    SELECT * FROM wcx_videos WHERE video_active = '0'
    UNION
    SELECT * FROM wcx_apps WHERE app_active = '0'
    UNION
    SELECT * FROM wcx_links WHERE link_active = '0'
    ";
        if( $this->num_rows( $query ) > 0 ) {    
            $count = $this->num_rows($query);
            return $count;
        }
    }

 public function num_rows( $query ) {
    $query = $this->link->query( $query );
    if( mysqli_error( $this->link ) ) {
        $this->log_db_errors( mysqli_error( $this->link ), $query, 'Fatal' );
        return mysqli_error( $this->link );
    }
    else {
        return mysqli_num_rows( $query );
    }
    mysqli_free_result( $query );
}
Updated Question with working Code
Source Link
CodeX
  • 1.1k
  • 2
  • 13
  • 19

Select 4 different named columns Conditional row count across 4 tables and return the count of all

Ive been trying this for daysI have the following function that works fine, i wantis there a better way to count the amount of inactiveItems()do it and will this be efficient if i have 100+ rows returned from 4 tables, all help appreciated.each table?

The database

Tables

  • wcx_articles
  • wcx_videos
  • wcx_apps
  • wcx_links

The corresponding _active column for each table

  • article_active
  • video_active
  • app_active
  • link_active

_active is a switch 1 or 0

This is my current function - it returns 0

        public function inactiveItemsfindInactiveItems() {
        
    $query = 
 "SELECT * FROM wcx_articles,wcx_videos,wcx_apps,wcx_links 
 WHERE wcx_articles.article_active='0'article_active AND= '0'
    UNION
    SELECT * FROM wcx_videos.video_active='0' WHERE video_active = '0'
AND    UNION
    SELECT * FROM wcx_apps.app_active='0' ANDWHERE app_active = '0'
    UNION
    SELECT * FROM wcx_links.link_active='0'"; WHERE link_active = '0'
    ";
        if( $this->num_rows( $query ) > 0 ) {   
            $count = $this->num_rows($query);
            return $count;
     }   }
   
  }

 public function num_rows( $query ) {
    $query = $this->link->query( $query );
    if( mysqli_error( $this->link ) ) {
        $this->log_db_errors( mysqli_error( $this->link ), $query, 'Fatal' );
        return mysqli_error( $this->link );
    }
    else {
        return mysqli_num_rows( $query );
    }
    mysqli_free_result( $query );
}

Select 4 different named columns across 4 tables and return the count of all

Ive been trying this for days, i want to count the amount of inactiveItems() from 4 tables, all help appreciated.

The database

Tables

  • wcx_articles
  • wcx_videos
  • wcx_apps
  • wcx_links

The corresponding _active column for each table

  • article_active
  • video_active
  • app_active
  • link_active

_active is a switch 1 or 0

This is my current function - it returns 0

 public function inactiveItems() {
        
$query = 
 "SELECT * FROM wcx_articles,wcx_videos,wcx_apps,wcx_links 
 WHERE wcx_articles.article_active='0' AND wcx_videos.video_active='0' 
AND wcx_apps.app_active='0' AND wcx_links.link_active='0'";

 if( $this->num_rows( $query ) > 0 ) {  
     $count = $this->num_rows($query);
     return $count;
     }      
  }

 public function num_rows( $query ) {
    $query = $this->link->query( $query );
    if( mysqli_error( $this->link ) ) {
        $this->log_db_errors( mysqli_error( $this->link ), $query, 'Fatal' );
        return mysqli_error( $this->link );
    }
    else {
        return mysqli_num_rows( $query );
    }
    mysqli_free_result( $query );
}

Conditional row count across 4 tables

I have the following function that works fine, is there a better way to do it and will this be efficient if i have 100+ rows returned from each table?

The database

Tables

  • wcx_articles
  • wcx_videos
  • wcx_apps
  • wcx_links

The corresponding _active column for each table

  • article_active
  • video_active
  • app_active
  • link_active

_active is a switch 1 or 0

This is my current function

        public function findInactiveItems() {
        
    $query = "SELECT * FROM wcx_articles WHERE article_active = '0'
    UNION
    SELECT * FROM wcx_videos WHERE video_active = '0'
    UNION
    SELECT * FROM wcx_apps WHERE app_active = '0'
    UNION
    SELECT * FROM wcx_links WHERE link_active = '0'
    ";
        if( $this->num_rows( $query ) > 0 ) {   
            $count = $this->num_rows($query);
            return $count;
        }
    }

 public function num_rows( $query ) {
    $query = $this->link->query( $query );
    if( mysqli_error( $this->link ) ) {
        $this->log_db_errors( mysqli_error( $this->link ), $query, 'Fatal' );
        return mysqli_error( $this->link );
    }
    else {
        return mysqli_num_rows( $query );
    }
    mysqli_free_result( $query );
}
Source Link
CodeX
  • 1.1k
  • 2
  • 13
  • 19

Select 4 different named columns across 4 tables and return the count of all

Ive been trying this for days, i want to count the amount of inactiveItems() from 4 tables, all help appreciated.

The database

Tables

  • wcx_articles
  • wcx_videos
  • wcx_apps
  • wcx_links

The corresponding _active column for each table

  • article_active
  • video_active
  • app_active
  • link_active

_active is a switch 1 or 0

This is my current function - it returns 0

 public function inactiveItems() {
        
$query = 
"SELECT * FROM wcx_articles,wcx_videos,wcx_apps,wcx_links 
WHERE wcx_articles.article_active='0' AND wcx_videos.video_active='0' 
AND wcx_apps.app_active='0' AND wcx_links.link_active='0'";

 if( $this->num_rows( $query ) > 0 ) {  
     $count = $this->num_rows($query);
     return $count;
     }      
 }

 public function num_rows( $query ) {
    $query = $this->link->query( $query );
    if( mysqli_error( $this->link ) ) {
        $this->log_db_errors( mysqli_error( $this->link ), $query, 'Fatal' );
        return mysqli_error( $this->link );
    }
    else {
        return mysqli_num_rows( $query );
    }
    mysqli_free_result( $query );
}