Jump to content

Variable passed through query (not the assigned value)


aikorei

Recommended Posts

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.

Link to comment
Share on other sites

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. =)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.