royboyy Posted August 19, 2008 Share Posted August 19, 2008 Hello, Could someone please steer me in the right direction? I'm creating a website for my internet radio station and i want to give my users the ability to view the playlist archive. I'm trying to create drop down boxes, that when a specific hour is selected, it will show all songs played within that hour. I have the drop down boxes and the database query, but as of now, it just loops the first song of the hour over and over. <?php // The functions contained in this script generate and process a php format date select object // Author: Ulysses J Ludwig // E-mail: [email protected] // Phone: 213.948.8278 require('config.php'); function Fn_date_select($In_field_name, $In_date_format_string, $In_unix_time) { // This function generates a date and or time function based on the format and default time that you enter if (!$In_unix_time) { $In_unix_time = time(); } for ($j=0;$j<strlen($In_date_format_string);$j++) { // looping through the format string $L_format_char = substr($In_date_format_string,$j,1); switch ($L_format_char) { // each character in the format string means something case "m": // numeric month ?> <select name=<?php echo $In_field_name . "[m]"?>> <?php for ($i=1;$i<13;$i++) { $L_var_month = date("$L_format_char",mktime(0,0,0,$i,15,2000)); if ($L_var_month == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print ("<option value=$i $L_selected>" . $L_var_month . "</option>\n"); } ?> </select> <?php break; case "F": // textual full month ?> <select name=<?php echo $In_field_name . "[m]"?>> <?php for ($i=1;$i<13;$i++) { $L_var_month = date("$L_format_char",mktime(0,0,0,$i,15,2000)); if ($L_var_month == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print ("<option value=$i $L_selected>" . $L_var_month . "</option>\n"); } ?> </select> <?php break; case "d": ?> <select name=<?php echo $In_field_name . "[d]"?>> <?php for ($i=1;$i<32;$i++) { if ($i == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$i</option>\n"); } ?> </select> <?php break; case "D": ?> <select name=<?php echo $In_field_name . "[d]"?>> <?php for ($i=1;$i<8;$i++) { $L_var_textual_day = date("$L_format_char",mktime(0,0,0,8,$i,1999)); if ($L_var_textual_day == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$L_var_textual_day</option>\n"); } ?> </select> <?php break; case "y": ?> <select name=<?php echo $In_field_name . "[y]"?>> <?php for ($i = 2007; $i <= (date($L_format_char) + ; $i++) // starting in 1997 { if ($i == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$i</option>\n"); } ?> </select> <?php break; case "Y": ?> <select name=<?php echo $In_field_name . "[y]"?>> <?php for ($i = 2007; $i <= (date($L_format_char) + 0); $i++) // starting in 1997 { if ($i == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$i</option>\n"); } ?> </select> <?php break; case "h": ?> <select name=<?php echo $In_field_name . "[h]"?>> <?php for ($i = 1; $i < 13; $i++) { if ($i == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$i</option>\n"); } ?> </select> <?php break; case "g": ?> <select name=<?php echo $In_field_name . "[h]"?>> <?php for ($i = 1; $i < 13; $i++) { if ($i == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$i</option>\n"); } ?> </select> <?php break; case "H": ?> <select name=<?php echo $In_field_name . "[h]"?>> <?php for ($i = 0; $i < 24; $i++) { if ($i == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$i</option>\n"); } ?> </select> <?php break; case "G": ?> <select name=<?php echo $In_field_name . "[h]"?>> <?php for ($i = 0; $i < 24; $i++) { if ($i == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$i</option>\n"); } ?> </select> <?php break; case "i": ?> <select name=<?php echo $In_field_name . "[i]"?>> <?php for ($i = 0; $i < 60; $i++) { if ($i == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$i</option>\n"); } ?> </select> <?php break; case "s": ?> <select name=<?php echo $In_field_name . "[s]"?>> <?php for ($i = 0; $i < 60; $i++) { if ($i == date("$L_format_char",$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=$i $L_selected>$i</option>\n"); } ?> </select> <?php break; case "a": ?> <select name=<?php echo $In_field_name . "[a]"?>> <?php // AM $L_text_time = "am"; if ($L_text_time == date(strtoupper($L_format_char),$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=1 $L_selected>$L_text_time</option>\n"); // PM $L_text_time = "pm"; if ($L_text_time == date(strtoupper($L_format_char),$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=2 $L_selected>$L_text_time</option>\n"); ?> </select> <?php break; case "A": ?> <select name=<?php echo $In_field_name . "[a]"?>> <?php // AM $L_text_time = "AM"; if ($L_text_time == date(strtoupper($L_format_char),$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=1 $L_selected>$L_text_time</option>\n"); // PM $L_text_time = "PM"; if ($L_text_time == date(strtoupper($L_format_char),$In_unix_time)) { $L_selected=" SELECTED "; } else { unset($L_selected); } print("<option value=2 $L_selected>$L_text_time</option>\n"); ?> </select> <?php break; default: echo $L_format_char; // not a recognized character, so echo it out } // end of switch } // end of for } function Fn_process_date_select($In_time_array) { // This function processes the date select object on submit if ($In_time_array[a]==2 and ($In_time_array[h] < 12)) { // the user chose pm $In_time_array[h] = $In_time_array[h] + 12; } else if ($In_time_array[a] == 1 and $In_time_array[h] == 12) { $In_time_array[h] = 0; } return mktime($In_time_array[h],$In_time_array[i],$In_time_array[s],$In_time_array[m],$In_time_array[d],$In_time_array[y]); } ?> <html> <p>Browse an hour by hour archive of our playlists using the selections below.</p> <form name=myform> <?php Fn_date_select("MyDateField","F d Y, h A",$Null); /* M */ ?> <input name="submit_pb" type="submit" value="Submit"> </form> <?php // To process the user entry back to php-unix time do this if ($_GET['submit_pb']) { $L_php_unix_time = Fn_process_date_select($_GET['MyDateField']); echo "The time entered was: " . date("F d, Y - h:00 A", $L_php_unix_time); $hour_begin = $L_php_unix_time; $hour_length = 60; $hour_time = strtotime("+$hour_length minutes", $hour_begin); if(!$date_passed) $date_passed=time(); $hour_end = $hour_time; //Database Query $db->open("SELECT songlist.*, historylist.listeners as listeners, DATE_FORMAT(historylist.date_played, '%h:%i %p') as mytime, historylist.requestID as requestID, historylist.date_played as starttime from songlist,historylist WHERE (historylist.songID = songlist.ID) AND (songlist.songtype='S') AND historylist.date_played > FROM_UNIXTIME($hour_begin) AND historylist.date_played < FROM_UNIXTIME($hour_end) GROUP BY songlist.ID ORDER BY songlist.date_played ASC"); $result = $db->row(); if($result > 0){ echo "<table border=2 align=\"center\" width=400>"; echo "<TR><TD>TIME<TD>ARTIST<TD>TITLE"; while($myrow = $result){ echo "<TR><TD>"; echo $myrow[mytime]; echo "<td>"; echo $myrow["artist"]; echo "<td>"; echo $myrow["title"]; } } } ?> </html> </body> </html> Thank you in advance for your suggestions. Link to comment https://forums.phpfreaks.com/topic/120445-select-a-specific-hour-from-drop-down-boxes/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.