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.

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

Note
: Unlike the
and
syntaxes,
and escape sequences for special characters will
not
be expanded when they occur in single quoted
s.

http://php.net/manual/en/language.types.string.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.