• Resolved whooami

    (@whooami)


    Ive been trying with no success to turn the result of a simple MySQL query that looks at one column and returns all of the items in a column, using WordPress’ built in db class, into a simple array.

    I found one other similar post that kind of helped, it changed the array, but still didnt provide the result I’m looking for.

    I’m trying to archive this simple one-dimensional array:

    Array ( [0] => cat [1] => dog )

    So far, manipulating the various wpdb query options, I’ve gotten this:

    Array ( [0] => Array ( [0] => cat ) [1] => Array ( [0] => dog ) )

    and,

    Array ( [0] => Array ( [id] => 14 [mysql-field] => cat ) [1] => Array ( [id] => 15 [mysql-field] => dog ) )

    The query is simple enough:

    $sql = "SELECT animals from $table_name";
    $pets = $wpdb->get_results($sql);

    Am I missing something really simple here? Or can anyone lend some advice?

Viewing 1 replies (of 1 total)
  • Thread Starter whooami

    (@whooami)

    for anyone interested here is the rather simple solution:

    $sql = 'select ID, blah from '.$table_name;
    		$things = array();
    		$results = $wpdb->get_results($sql );
    		foreach( $results as $result )
    		$things[] = $result->blah;
Viewing 1 replies (of 1 total)
  • The topic ‘turn wpdb->get_results…. into a single dimensional array’ is closed to new replies.