PHP Audio Array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xkrazykidx
    New Member
    • Jun 2010
    • 6

    PHP Audio Array?

    Im still new to MySQL and know my way around PHP but not fully.

    I'm creating a Audio Database that can be viewed here : http://elixclothing.com/connection.php

    Im trying to figure out how to query all of the audio locations and put them in my media player which can be played according to which audio button is pressed.

    I have a few ideas, I was wondering if I should move the audiolocation column to a new table so that I select them easier and not stress out my current table. Or follow something along the lines of this http://bytes.com/topic/php/answers/7...y-one-row-time

    My current code is below:

    Code:
    <html>
    <head>
    <title>Test</title>
    <script src="ac_quicktime.js" language="JavaScript" type="text/javascript"></script>
    </head>
    <body>
    <script type="text/javascript"> 
    function toggleVisibility() {
    	document.getElementById("toggleMe").style.display = "";
    	if(document.getElementById("toggleMe").style.visibility == "hidden" ) {
    		document.getElementById("toggleMe").style.visibility = "visible";
    	}
    	else {
    	document.getElementById("toggleMe").style.visibility = "hidden";
    	}
    }
    function toggleDisplay() {
    	document.getElementById("toggleMe").style.visibility = "visible";
    	if(document.getElementById("toggleMe").style.display == "none" ) {
    		document.getElementById("toggleMe").style.display = "";
    	}
    	else {
    		document.getElementById("toggleMe").style.display = "none";
    	}
    }
    </script> 
    
    <table border="1" width="75%" cellpadding="2" cellspacing="2"> 
    <tr> 
    <td align="center">Cue Code</td> 
    <td align="center">Cue Title</td> 
    <td align="center">Cue Description</td> 
    <td align="center">Time</td>
    <td align="center"></td>
    </tr> 
    <br />
    
    <?php
    mysql_connect("***", "***", "***") or die(mysql_error());
    echo "Connected to MySQL<br /><hr />";
    mysql_select_db("elixclot_music") or die(mysql_error());
    echo "Connected to Database<br /><hr />";
    $query = "SELECT * FROM tracks";
    $result = mysql_query($query) or die(mysql_error());
    while($line = mysql_fetch_array($result)) {
    	
    	//        Audio Player Begins
    echo "<div display='none' id='toggleMe' >
    <p>".$line['cue_code']."</p>
    <p>".$line['cue_title']."</p>
    <OBJECT CLASSID='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' WIDTH='290' HEIGHT='20'
    CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'>
    <PARAM name='SRC' VALUE=".$line['cue_code'].">
    <PARAM name='AUTOPLAY' VALUE='true'>
    <PARAM name='CONTROLLER' VALUE='true'>
    <EMBED src=".$line[audiolocation]." WIDTH='290' HEIGHT='20'
    AUTOPLAY='false' CONTROLLER='true'
    PLUGINSPAGE='http://www.apple.com/quicktime/download/'>
    </EMBED>
    </OBJECT>
     </div>";
       //        Audio Player Ends
    
    
    
    echo "<td align='center'>".$line['cue_code']."</td>"; 
    echo "<td align='center'>".$line['cue_title']."</td>"; 
    echo "<td align='center'>".$line['cue_description']."</td>"; 
    echo "<td align='center'>".$line['time']."</td>";
    echo "<td align='center'><a href='#' onclick='toggleDisplay();'><img src='speaker_dark.gif' border=0></a>";
    echo "</tr>"; 
    }
    ?>
    </table>
    </body>
    </html>
    Any help would be greatly appreciated.
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    #2
    I can help a little bit. First, I'm curious as to why you're using a separate div for each track, you don't need to do that. I'm also trying to figure out why you're using quicktime when you should instead use something like a flash-based player.

    First off, you have to understand that you're setting multiple divs, all with the same ID. Your javascript is using the hard-coded ID "toggleMe" to show or hide the player div. Since they all have the same ID this causes issues. You should have each track in the database have it's own unique ID which you could append to the div's ID, for example:

    track_id = 0
    cue_code = OPUS10.013_12
    cue_title = She'll Be The One ver. 2
    cue_description = underscore
    time = 01:48:00

    Then your code would use that unique track_id as the div's ID:

    <div id="toggleMe_0" ...

    then your javascript function toggleDisplay() would change to toggleDisplay(d ivID) and you'd replace all hardcoded instances of "toggleMe" to divID in the actual function, like below. I also made a variable named obj, so that you don't have to type the whole document.getEle mentById line so many times:

    Code:
    function toggleDisplay(divID) {
      var obj = document.getElementById(divID);
      obj.style.visibility = "visible";
      if(obj.style.display == "none" ) {
        obj.style.display = "";
        } else {
        obj.style.display = "none";
        }
      }
    You are also forgetting to print an opening tag for a table row, you're only printing the closing tag which is making all of your information print on 1 row. The fix is easy:

    Code:
    //        Audio Player Ends
    
    
    echo "<tr>";
    echo "<td align='center'>".$line['cue_code']."</td>";
    ...
    Just insert the echo "<tr>"; line before you start printing your table data tags.

    One more thing, you should add "return: false;" (without the quotes) directly after your toggleDisplay() call in the onclick attribute, this will stop the link from actually navigating in the browser (yes, a # is still technically navigation.)

    And again, you should look into a flash-based player, you can usually feed data to it through a javascript call and you'll only have to print one, plus Flash is more universal. Since I want you to do that instead of using Quicktime, I'm only going to point out a slight error in your audio player printing code in passing, because I don't think you should use it:

    Code:
    <PARAM name='SRC' VALUE=".$line['cue_code'].">
    [...]
    <EMBED src=".$line[audiolocation]." WIDTH='290' HEIGHT='20'...
    For starters, the Object param src and the embed src should be the same thing, you're setting 2 different values. Secondly, you forgot the single quotes in the embed src:

    $line[audiolocation]

    Should be:

    $line['audiolocation']

    Anyway, I hope this gives you something to work with, let me know if yu have any more questions and I'll do my best to help!

    Comment

    • xkrazykidx
      New Member
      • Jun 2010
      • 6

      #3
      Originally posted by HaLo2FrEeEk
      I can help a little bit. First, I'm curious as to why you're using a separate div for each track, you don't need to do that. I'm also trying to figure out why you're using quicktime when you should instead use something like a flash-based player.

      First off, you have to understand that you're setting multiple divs, all with the same ID. Your javascript is using the hard-coded ID "toggleMe" to show or hide the player div. Since they all have the same ID this causes issues. You should have each track in the database have it's own unique ID which you could append to the div's ID, for example:

      track_id = 0
      cue_code = OPUS10.013_12
      cue_title = She'll Be The One ver. 2
      cue_description = underscore
      time = 01:48:00

      Then your code would use that unique track_id as the div's ID:

      <div id="toggleMe_0" ...

      then your javascript function toggleDisplay() would change to toggleDisplay(d ivID) and you'd replace all hardcoded instances of "toggleMe" to divID in the actual function, like below. I also made a variable named obj, so that you don't have to type the whole document.getEle mentById line so many times:

      Code:
      function toggleDisplay(divID) {
        var obj = document.getElementById(divID);
        obj.style.visibility = "visible";
        if(obj.style.display == "none" ) {
          obj.style.display = "";
          } else {
          obj.style.display = "none";
          }
        }
      You are also forgetting to print an opening tag for a table row, you're only printing the closing tag which is making all of your information print on 1 row. The fix is easy:

      Code:
      //        Audio Player Ends
      
      
      echo "<tr>";
      echo "<td align='center'>".$line['cue_code']."</td>";
      ...
      Just insert the echo "<tr>"; line before you start printing your table data tags.

      One more thing, you should add "return: false;" (without the quotes) directly after your toggleDisplay() call in the onclick attribute, this will stop the link from actually navigating in the browser (yes, a # is still technically navigation.)

      And again, you should look into a flash-based player, you can usually feed data to it through a javascript call and you'll only have to print one, plus Flash is more universal. Since I want you to do that instead of using Quicktime, I'm only going to point out a slight error in your audio player printing code in passing, because I don't think you should use it:

      Code:
      <PARAM name='SRC' VALUE=".$line['cue_code'].">
      [...]
      <EMBED src=".$line[audiolocation]." WIDTH='290' HEIGHT='20'...
      For starters, the Object param src and the embed src should be the same thing, you're setting 2 different values. Secondly, you forgot the single quotes in the embed src:

      $line[audiolocation]

      Should be:

      $line['audiolocation']

      Anyway, I hope this gives you something to work with, let me know if yu have any more questions and I'll do my best to help!
      I really cant thank you enough! You have finally given me an intelligent response that relates to what I am trying to do. Ive spent so many times on other forums trying to get some help.

      I have made the additions you recommended, also I do have a "ID" column in my table.

      Code:
      <html>
      <head>
      <title>Test</title>
      <script src="ac_quicktime.js" language="JavaScript" type="text/javascript"></script>
      </head>
      <body>
      <script type="text/javascript"> 
      function toggleDisplay(divID) {
        var obj = document.getElementById(divID);
        obj.style.visibility = "visible";
        if(obj.style.display == "none" ) {
          obj.style.display = "";
          } else {
          obj.style.display = "none";
          }
        }
      </script> 
       
      <table border="1" width="75%" cellpadding="2" cellspacing="2"> 
      <tr> 
      <td align="center">Cue Code</td> 
      <td align="center">Cue Title</td> 
      <td align="center">Cue Description</td> 
      <td align="center">Time</td>
      <td align="center"></td>
      </tr> 
      <br />
       
      <?php
      mysql_connect("localhost", "elixclot_haywars", "mister") or die(mysql_error());
      echo "Connected to MySQL<br /><hr />";
      mysql_select_db("elixclot_music") or die(mysql_error());
      echo "Connected to Database<br /><hr />";
      $query = "SELECT * FROM tracks";
      $result = mysql_query($query) or die(mysql_error());
      while($line = mysql_fetch_array($result)) {
       
          //        Audio Player Begins
      echo "<div display='none' id='toggleMe_1' >
      <p>".$line['cue_code']."</p>
      <p>".$line['cue_title']."</p>
      <OBJECT CLASSID='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' WIDTH='290' HEIGHT='20'
      CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'>
      <PARAM name='SRC' VALUE=".$line['cue_code'].">
      <PARAM name='AUTOPLAY' VALUE='true'>
      <PARAM name='CONTROLLER' VALUE='true'>
      <EMBED src=".$line['audiolocation']." WIDTH='290' HEIGHT='20'
      AUTOPLAY='false' CONTROLLER='true'
      PLUGINSPAGE='http://www.apple.com/quicktime/download/'>
      </EMBED>
      </OBJECT>
       </div>";
         //        Audio Player Ends
       
       
      echo "<tr>";
      echo "<td align='center'>".$line['cue_code']."</td>"; 
      echo "<td align='center'>".$line['cue_title']."</td>"; 
      echo "<td align='center'>".$line['cue_description']."</td>"; 
      echo "<td align='center'>".$line['time']."</td>";
      echo "<td align='center'><a href='#' onclick='toggleDisplay(divID);'><img src='speaker_dark.gif' border=0></a>";
      echo "</tr>"; 
      }
      ?>
      </table>
      </body>
      </html>
      But I want to switch to a flash player like you suggested. I did a quick Google search and found this http://www.flamplayer.com/, is this a good player to use? I was going for simplicity. Also an example for what I was going for was this site http://opus1.o1engine.com/

      again THANK YOU! THANK YOU!

      Comment

      • HaLo2FrEeEk
        Contributor
        • Feb 2007
        • 404

        #4
        That player would work, you'd just build a dynamic playlist in the format that the player reads.

        And are you trying to build something exactly like that example site? Sorting by genre, artist, album, title, etc? That's quite a bit of work for somethig that's already been done to death.

        Comment

        • xkrazykidx
          New Member
          • Jun 2010
          • 6

          #5
          Great ill start working on putting it together.

          Unfortunately yes, im working with a start-up audio production company and this is how they want to organize their audio clips. They wanted their site to mimic Opus's site almost to the T.

          Comment

          • HaLo2FrEeEk
            Contributor
            • Feb 2007
            • 404

            #6
            Looks like you've got quite a bit of work ahead of you then. You'll want to start by clearly defining, in your database, individual details about every track. Don't wait til later, do it now while there are only a few tracks to add the data to and not hundreds.

            Comment

            • xkrazykidx
              New Member
              • Jun 2010
              • 6

              #7
              Originally posted by HaLo2FrEeEk
              Looks like you've got quite a bit of work ahead of you then. You'll want to start by clearly defining, in your database, individual details about every track. Don't wait til later, do it now while there are only a few tracks to add the data to and not hundreds.
              Thanks for all your help! You have been great! I wish I would have came here first! Luckily I have told the other team members to work on a CSV with all the information about each track and I also gave them outlines :)

              Thanks again!

              Comment

              • HaLo2FrEeEk
                Contributor
                • Feb 2007
                • 404

                #8
                if you need it I've got a php script that can take a CSV file and translate it into an SQL query to mass import into a database, unless your database admin panel already lets you import a CSV.

                Also, don't forget to mark a best answer : )

                Comment

                • captainB
                  New Member
                  • Aug 2009
                  • 23

                  #9
                  I was reading this thread out of interest, and I must say that I'm impressed with the effort shown by HaLo2FrEeEk to answer the question.

                  You elevate the quality of this forum!

                  Thanks!

                  Comment

                  • xkrazykidx
                    New Member
                    • Jun 2010
                    • 6

                    #10
                    Originally posted by HaLo2FrEeEk
                    if you need it I've got a php script that can take a CSV file and translate it into an SQL query to mass import into a database, unless your database admin panel already lets you import a CSV.

                    Also, don't forget to mark a best answer : )
                    Hmm I tried out FlamPlayer its great but unfortunately does not accomplish the task I was looking for. It automatically adds tracks to a database but does not include all the extra fields which im guessing I would have to input manually.

                    Also If i would like to add a track to the page, example where a user clicks on the listen button. I wouldnt be able to link that one track as FLAM is more about making playlists.

                    Also my Database allows importing of CSV's but thanks!
                    This project is becoming daunting and it seems like im never going to be able to complete it.

                    HaLo2FrEeEk I was wondering if you have the time to explain a little more about the "ID" idea. That seems like its more fitting to what I would like to accomplish.

                    Thanks again for all your help.

                    Comment

                    • HaLo2FrEeEk
                      Contributor
                      • Feb 2007
                      • 404

                      #11
                      A few more things I'd like to touch on. It still looks like you're printing the player code for each individual track, when I click the little play icon for a song, it actually hides that track's player instead of making it visible.

                      You're also still forgetting to print your table row tag at the beginning of each track:

                      Code:
                      //        Audio Player Ends
                      
                      
                      echo "<tr>";
                      echo "<td align='center'>".$line['cue_code']."</td>";
                      ...
                      You need to do that.

                      Other than that, looking good.

                      Comment

                      • xkrazykidx
                        New Member
                        • Jun 2010
                        • 6

                        #12
                        Originally posted by HaLo2FrEeEk
                        A few more things I'd like to touch on. It still looks like you're printing the player code for each individual track, when I click the little play icon for a song, it actually hides that track's player instead of making it visible.

                        You're also still forgetting to print your table row tag at the beginning of each track:

                        Code:
                        //        Audio Player Ends
                        
                        
                        echo "<tr>";
                        echo "<td align='center'>".$line['cue_code']."</td>";
                        ...
                        You need to do that.

                        Other than that, looking good.
                        Thanks Ill add the code when I get home, I think to better explain my issue is that I would like to display only 1 media player and when I click the play button it plays that table specific song. Im trying to finish this before friday...which is seeming impossible.

                        HaLo2FrEeEk you have been a great help so far thanks.

                        I am having a hard time passing the audiolocation to the audio player and making the player hidden so that when I click listen it displays the hidden player. Also if I click the next track to listen it should (Not hide the player) but just load up that track and play.

                        Edit: Made an advancement and changed my Code, hopefully this works. Im just having an issue with line 77.

                        Code:
                        <html>
                        <head>
                        <title>Test</title>
                        <script src="ac_quicktime.js" language="JavaScript" type="text/javascript"></script>
                        </head>
                        <body>
                        
                        <script type="text/javascript"> 
                        function toggleDisplay(divID) {
                          var obj = document.getElementById(divID);
                          obj.style.visibility = "visible";
                          if(obj.style.display == "none" ) {
                            obj.style.display = "";
                            } else {
                            obj.style.display = "none";
                            }
                          }
                        </script> 
                        
                        <?php
                          mysql_connect("***", "***", "***") or die(mysql_error());
                          echo "Connected to MySQL<br /><hr />";
                         mysql_select_db("elixclot_music") or die(mysql_error());
                          echo "Connected to Database<br /><hr />";
                          $query = "SELECT * FROM tracks";
                        
                          $result = mysql_query($query) or die(mysql_error());
                        $line = mysql_fetch_array($result);
                        ?>
                        
                        <?php
                        
                        $cue_id = $_GET['cue'];
                            
                        if($cue_id == $line['cue_code'])
                            {    
                            $audioURL = $line['audiolocation'];
                            return $audioURL;
                            }
                        
                        ?>
                        
                             //        Audio Player Begins
                        echo "<div display='none' id='toggleMe' >
                        <OBJECT CLASSID='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' WIDTH='290' HEIGHT='20'
                        CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'>
                        <PARAM name='SRC' VALUE=".$line['cue_code'].">
                        <PARAM name='AUTOPLAY' VALUE='true'>
                        <PARAM name='CONTROLLER' VALUE='true'>
                        <EMBED src="<?php $audioURL; ?>" WIDTH='290' HEIGHT='20'
                        AUTOPLAY='false' CONTROLLER='true'
                        PLUGINSPAGE='http://www.apple.com/quicktime/download/'>
                        </EMBED>
                        </OBJECT>
                        </div>";
                            //        Audio Player Ends
                        
                         
                        <table border="1" width="75%" cellpadding="2" cellspacing="2"> 
                        <tr> 
                        <td align="center">Cue Code</td> 
                        <td align="center">Cue Title</td> 
                        <td align="center">Cue Description</td> 
                        <td align="center">Time</td>
                        <td align="center"></td>
                        </tr> 
                        <br />
                         
                        <?php
                        
                        while($line) 
                            {
                        echo "<td align='center'>".$line['cue_code']."</td>"; 
                        echo "<td align='center'>".$line['cue_title']."</td>"; 
                        echo "<td align='center'>".$line['cue_description']."</td>"; 
                        echo "<td align='center'>".$line['time']."</td>";
                        echo "<td align='center'><a href="<?php echo '?cue='.$line['cue_code']; ?>" onclick='toggleDisplay();'><img src='speaker_dark.gif' border=0></a>";
                          echo "</tr>"; 
                          }
                         ?>
                          </table>
                           </body>
                           </html>

                        Comment

                        Working...