Support » Fixing WordPress » SQL Query doesn't work

  • rugbywallabies


    Hi my page won’t load apparently something wrong with my query but i tried many ways. stuck 🙁

    //$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];


Viewing 1 replies (of 1 total)
  • vtxyzzy


    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 />";
Viewing 1 replies (of 1 total)
  • The topic ‘SQL Query doesn't work’ is closed to new replies.