WordPress.org

Forums

MySQL query fails (4 posts)

  1. LDMartin1959
    Member
    Posted 1 year ago #

    Trying to modify the header.php file. Have added the following:

    $q1=mysql_query("SELECT * FROM 'table_name' WHERE 'type'='1' AND 'cat'='.$post->ID.' ");

    When I do a var_dump($q1); I get FALSE. What am I missing here?

  2. catacaustic
    very awesome
    Posted 1 year ago #

    You should be using the standard $wpdb object for your queries as you might not be able to get to the mysql_query() function using the connection that is set up.

    Oh, and you've really got the quotes wrong in your query too, which is most likely the problem.

    $q1 = $wpdb->get_results ("SELECT * FROM 'table_name' WHERE 'type' = '1' AND 'cat' = ".$post->ID);

  3. LDMartin1959
    Member
    Posted 1 year ago #

    Found the answer. When I used MySQL to create the query, it was putting search values in quotes which was incorrect.

  4. LDMartin1959
    Member
    Posted 1 year ago #

    catacaustic, didn't see your post before I posted my follow up. Yes, you are corrct about the quote marks (I blame MySQL for lying to me). I'm not a WP, MySQL or PHP expert -- I'm not even good enough to be a beginner -- so I'm not sure what you mean by he standard $wpdb object. Could you explain that for me?

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic