Title: Functions.php issue Sql Query
Last modified: August 22, 2016

---

# Functions.php issue Sql Query

 *  [gtm1ldy](https://wordpress.org/support/users/gtm1ldy/)
 * (@gtm1ldy)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/functionsphp-issue-sql-query/)
 * I have a sql query that returns no data. I have made these queries 1000’s of 
   times. I am hoping for a little input here as our functions file is over 3000
   lines long.
 * Why would the first query not function but the second one does?
 * This query returns a blank result (I have MANY queries that do work with the 
   same format (” around the variables)):
 * $companyid = $wpdb->get_var($wpdb->prepare(“SELECT business_id FROM $usertable
   WHERE $id = %d”, $uid));
 * This query returns the correct result (removed the ” around the variables):
 * $companyid = $wpdb->get_var($wpdb->prepare(“SELECT business_id FROM ‘$usertable’
   WHERE ‘$id’ = %d”, $uid));

Viewing 1 replies (of 1 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/functionsphp-issue-sql-query/#post-5425885)
 * Becuase in MySQL the single-quote is for referneceing values, not table/column
   names. That means that when you have `WHERE '$id'` in there it’s taking the $
   id value as a value of a column, not a column name.
 * You’ve already found the anser ot this – don’t put single-quotes around the column
   names, only the values that are found in columns.
 * Example…
 * `SELECT col_1, col_2 FROM table_name WHERE col_3 = 'value' ORDER BY id ASC`

Viewing 1 replies (of 1 total)

The topic ‘Functions.php issue Sql Query’ is closed to new replies.

## Tags

 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [sql-query](https://wordpress.org/support/topic-tag/sql-query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/functionsphp-issue-sql-query/#post-5425885)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
