aikorei Posted February 25, 2013 Share Posted February 25, 2013 This is probably a no-brainer, but I'm just not seeing where the problem lies. I've written two pieces of .php for a WordPress site, one copied from the other. One works, one doesn't. The piece that works is: $k_user_id = $current_user->ID; $k_table = $wpdb->prefix . 'bp_friends'; $k_friends1 = $wpdb->get_col( "SELECT initiator_user_id FROM $k_table WHERE friend_user_id = $k_user_id AND is_confirmed = 1" ); The piece that doesn't is: $app_table = $wpdb->prefix . 'app_appointments'; $sql = $wpdb->prepare('SELECT COUNT(worker) FROM $app_table WHERE worker = $user_id AND status = "completed" '); $app_count = $wpdb->query($sql) The error that's populating in my error log for the second statement is: WordPress database error Table 'my_table.$app_table' doesn't exist for query It appears that the actual variable "$app_table" is getting passed through to the database instead of the variable's value, "app_appointments". Can anyone point where I'm going wrong here? Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 25, 2013 Share Posted February 25, 2013 Your first query is inside "..." Your second is inside '...' Variables inside single quotes are not interpreted, they are literal strings Quote Link to comment Share on other sites More sharing options...
aikorei Posted February 25, 2013 Author Share Posted February 25, 2013 Ah. That's the first I'd heard of that. I read somewhere that single quotes and double quotes were identical, but they apparently left out that piece of information. Thanks for the help (again)!! I really appreciate it. It works now. =) Quote Link to comment Share on other sites More sharing options...
Barand Posted February 26, 2013 Share Posted February 26, 2013 Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings. http://php.net/manual/en/language.types.string.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.