WordPress.org

Ready to get started?Download WordPress

Forums

Query finding names beginning with A-D (2 posts)

  1. SFGolfer
    Member
    Posted 10 months ago #

    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?

  2. SFGolfer
    Member
    Posted 10 months ago #

    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

Reply

You must log in to post.

About this Topic

Tags