WordPress.org

Ready to get started?Download WordPress

Forums

get_row() with custom table and where statement returns null (2 posts)

  1. togamario
    Member
    Posted 1 year ago #

    In PHP I've used the following code in attempt to pull a single row to return the results in JSON format. If I remove my WHERE statement, the record returns fine (assuming I'm just testing with one record in the table.) If I add the WHERE statement back, it returns NULL. The exact same query, when pasted into phpmyadmin's query tool, produces the desired record. Highly annoying, so if anyone could please point out what I've done wrong I would greatly appreciate it!

    For the sake of example, let's assume I can confirm that "stringId1" (which is a varchar) does exist in the DB and I've culled the JSON output just to demonstrate the syntax I'm using.

    $queryString = "SELECT * FROM wp_sne WHERE id = 'stringId1'";
    $result = $wpdb->get_row($queryString);
    
    if ($result)
    	echo json_encode(array("id" => $result->id));

    POST Response: {"id":null}

  2. togamario
    Member
    Posted 1 year ago #

    Was this the incorrect location to post this question?

Topic Closed

This topic has been closed to new replies.

About this Topic