php - SQL for related videos -


what need query related videos in page shows video youtube. however, should choose related videos database. table structure is:

id, privatepublic, singer, title, datetime, gender, difficulty, ytid, lang

title : (title of song), ytid : yotube id of video, lang : language of song, difficulty : ranged 0 10.

requirements:

  1. privatepublic should 1
  2. gender should same current video
  3. at top same singer videos should displayed sorted datetime
  4. after "singer" section @ 3, should display songs same gender , closest difficulty .
  5. max number of videos related should 5.

i beginner sql. thank answers.

for used integrated php:

$qry_select="select songs.* songs (((songs.gender)='".$_session['gender']."')) ,  (((songs.ytid)<>'".$_session['ytid']."')) ,  (((songs.privatepubblic)=1)) ,           (((songs.lang)='".$_session['songlang']."')) order rand()   limit 0,5;"; 

after 2-3 days of trial finded code: (songinfo comes get)

(select songs.* songs author = '".$songinfo['author']."'  , lang='".$songinfo['lang']."'  , title<>'".$songinfo['title']."'  order datetime desc limit 2)  union  (select * `songs` gender='".$songinfo['gender']."'  , lang='".$songinfo['lang']."'  , title<>'".$songinfo['title']."'  order abs(difficulty-4) limit 5)limit 5 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -