1

Ok, I have two tables: points and videos. I only want a video to show if the logged in user hasn't already been awarded points for watching that particular video.

The points db structure: id, special, user and points.

Special is the unique id of the video.

The videos db structure: id, title, points, src, photo, token, special.

There are multiple pages on this site. Token tells the video which page that video is ssigned to. Special is a special id for only that video and correlates to the special in the points db

--

This is the SQL Query I basicially want to say: $db->query("SELECT * FROM videos WHERE token='$id' AND num_rows OF user='$user' AND special='$special' == 0 FROM TABLE points");

Now I know this is not the proper format to write SQL Queries, but this is what I want in human. How do I translate this request to SQL?

1 Answer 1

0

You just need to join videos, points tables using the special column.

select count(*) from videos a join points b on (a.special = b.special) where b.user = '$user' and a.token = '$id';

This count will be 0 if the user has not watched the video.

1
  • Thanks, but how would I fetch the results from this SQL Query? From the video db, I want to get the title, photo,points,src & special. Previously, I did this by $special_video = $fetch_videos["special"];. How does this change with the new SQL query? Apr 25, 2017 at 4:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.