Support » Fixing WordPress » MySQL query fails

  • 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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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);

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

    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?


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘MySQL query fails’ is closed to new replies.