I really wasn't sure how to title this post, so I hope I drew some eyes. My php and mysql knowledge is limited, at best, and after much googling and sifting through CCK templates and phpAdmin, I'm hoping someone out there can help.
I'm displaying YouTube videos on my Drupal (5.1) site in a few different ways. First, I have a content type Video and on the home page I use a view to display one video at random from all of the videos entered as content type video. That works fine.
Second, I'm trying to display videos on certain nodes on the site if they're associated with that node. For instance, on the Florida page I want to show only videos tagged as Florida. The catch is that instead of showing the videos as a "list" I've got a little javascript function that uses innerHTML to refresh the video window when a button is clicked. So the page starts off displaying "Florida Video #1" and when the Next button is clicked, it moves onto "Florida Video #2" and so on. This works fine with the URLs for the videos hard coded into the javascript function and calls.
What I want is to change the Javascript & buttons so that instead of refreshing with a hard-coded YouTube URL, a button click scans my drupal database for the next video tagged with "Florida" (or with "New York" for the New York page, and so on). Creating a separate view per page (i.e. "View: Florida_Videos," View:NY_Videos" and so on) and then using the buttons to display one video at a time from those views seems like it might work but it'd be really clunky.
My idea was to basically search the database for content whose type is video and that is tagged with the same state name as the active page. So when I enter a video, I fill in a field with the URL and another field with a tag for state name. I'm thinking I need some kind of a SELECT phrase that looks to pull the URLs for all nodes of content type Video that are also tagged with the appropriate state name.
I'd then need to be able to use those URLs in my javascript function - basically when the Next button is clicked, to grab the next URL (i.e. the one for "Florida Video #2") and stick it into a variable to use in my innerHTML call. Then if Next is clicked again, grab the next URL in line ("Florida Video #3") and so on. If there aren't any more URLs to grab (rows in the query results) then I cycle back to the first one.
Does that make sense? Any thoughts on how to do it? Can I code it to parse the current page's state name (taxonomy) and use that to compare against entries in the database? Is there an easier way to do it with views or something else inside of drupal as opposed to writing a sql query? If it is a sql query, can anyone help with the syntax?
Thanks