WHERE function on Database
Question
I m trying to get an specific row in user_meta table, I just want the row that has the same ID as the author and the meta key is “reffer”. The first part of the code is working fine, I m able to get all the data from the user ID, but when I try to add an extra WHERE, I get problems:
AND WHERE meta_key = "reffer"; (Thats the part with the problem, the whole code is below)
<?php global $wpdb;
$user_id = $post->post_author;
$table_name = "mydb_usermeta";
$sql = "SELECT * FROM ".$table_name." WHERE user_id = ".intval($user_id) AND WHERE meta_key = "reffer";
$result = $wpdb->get_results($sql);
if(!empty($result))
{
foreach($result as $row){
echo "ID: ". $row->meta_value;
}
} ?>
0
code, database, mysql, php, post-meta
3 years
2020-04-03T04:50:53-05:00
2020-04-03T04:50:53-05:00 0 Answers
83 views
0
Leave an answer