WordPress.org

Forums

SQL Query doesn't work (2 posts)

  1. rugbywallabies
    Member
    Posted 2 years ago #

    Hi my page won't load apparently something wrong with my query but i tried many ways. stuck :(

    <?php
    //$sQuery = 'SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key=property_for_sale_details_0_bathrooms';
    $sQuery = 'SELECT meta_value FROM '.$wpdb->postmeta.' WHERE meta_key="property_for_sale_details_0_bathrooms" GROUP BY meta_value';

    echo $sQuery;
    $myrows = $wpdb->get_results($sQuery());
    echo $myrows; //echo $myrows[0];

    ?>

  2. vtxyzzy
    Member
    Posted 2 years ago #

    First, the call to get_results is being passed an incorrect parameter. The correct syntax is this:

    $myrows = $wpdb->get_results($sQuery);

    Second, the contents of $myrows is an array of objects. You would display them like this:

    foreach ($myrows as $row) {
       echo "$row->meta_value<br />";
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.