WordPress.org

Support

Support » How-To and Troubleshooting » Query finding names beginning with A-D

Query finding names beginning with A-D

  • I am trying to find player names beginning with A-D.

    I tried using the query below but it returns an empty set but the query does work in phpMyAdmin:

    WordPress code (returns empty set):

    $quicknavstr = “REGEXP ‘^[A-E].*$'”;
    $players = $wpdb->get_results( $wpdb->prepare( “SELECT player_name FROM participants WHERE (player_name NOT LIKE ‘%%team%%’ AND player_name %s) GROUP BY player_name ORDER BY player_name ASC”, $quicknavstr ), ARRAY_A );

    phpMyAdmin query (works, returns correct names):

    SELECT player_name FROM participants WHERE (player_name NOT LIKE ‘%%team%%’ AND player_name REGEXP ‘^[A-E].*$’) GROUP BY player_name ORDER BY player_name ASC

    Any ideas?

Viewing 1 replies (of 1 total)
  • Update.

    I get this when using $wpdb->show_errors();

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”REGEXP \’^[A-E].*$\”) GROUP BY player_name ORDER BY player_name ASC’ at line 1]
    SELECT player_name FROM pcgcwp_participants_database WHERE (player_name NOT LIKE ‘%team%’ AND player_name ‘REGEXP \’^[A-E].*$\”) GROUP BY player_name ORDER BY player_name ASC

Viewing 1 replies (of 1 total)
  • The topic ‘Query finding names beginning with A-D’ is closed to new replies.