mysql - Wordpress SQL Query to combine column data for all rows -
i have wordpress plugin allows users save favorite posts. in wordpress mysql database, table looks following:
id | user_id | post_id -------+---------+------------ 1 | 1 | 3,4,5,6,7,8 2 | 2 | 5,7,8,10 3 | 5 | 3,6,8,10
i'm looking take post_id
numbers, , combine them variable can foreach
them find how many matches there current post i'm reading.
for example, if i'm reading post id 10, want able see there 2 people have saved favorites.
i've tried $data = $wpdb->get_var("select post_id $table_name");
, var_dump($data);
returns my favorite posts, not all favorite posts.
although did play devils advocate in comments regarding normalization, table layout seem pretty braindead. however, if unable normalize database tables , have work have, can technically ask rather hacky sql statement:
select count(user_id) totalwishes table_name ( (post_id 'n,%') or (post_id '%,n,%') or (post_id '%,n') )
where n in example number of post.
i felt dirty writing that, in strictest interpretation of question, query should you're looking for.
Comments
Post a Comment