Skip to:
Content
Pages
Categories
Search
Top
Bottom

Line 186 bp-activity-classes.php – SELECT *


  • LPH2005
    Participant

    @lph2005

    From Line 186 of the bp-activity-classes.php:

    $activities = $wpdb->get_results( $wpdb->prepare( “SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) ORDER BY date_recorded {$sort} $pag_sql” ) );

    I’m just learning here (so please be gentle) – is there a reason the SELECT * is used rather than specific tables? Is the * necessary? I’m just curious as I’m reading the code to see what’s there … because isn’t * taxing to the server and faster to provide the specific tables?

Viewing 4 replies - 1 through 4 (of 4 total)

  • Jeff Sayre
    Participant

    @jeffsayre

    The “*” after the SELECT statement says that you want to return all the fields of all the records in the table named {$bp->activity->table_name} that meet the search specifications. It does not mean select all tables. Therefore, for each row of the table that meets the requirements of the query, all the fields (columns) in that row will be returned in the recordset.

    http://www.w3schools.com/sql/default.asp


    LPH2005
    Participant

    @lph2005

    Figures I’d use the wrong word “tables” versus “fields” … I knew what I meant .. but am clearly a novice :)

    OK. I was reading that SELECT * is taxing on the server and it’s better to specify the “fields” .. so in that statement … are all the fields required?

    Thanks Jeff for the link. In fact, in that example:

    SELECT Company, Country FROM Customers WHERE Country ‘USA’

    See how they don’t use SELECT * but SELECT Company, Country … that’s really my question for learning today :)

    It’s all down to what the query needs to do. If it needs to return every field from the records in a table, you may as well use a star, but if you only needed a particular column or two (or three, etc), then you just query for those specific columns.


    LPH2005
    Participant

    @lph2005

    Thank you. It’s all about learning :)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Line 186 bp-activity-classes.php – SELECT *’ is closed to new replies.
Skip to toolbar