wellscam Posted September 22, 2008 Share Posted September 22, 2008 I have this query that sorts through an Access database and pulls out a list of all the calls that took place on a specific extension. The query works for pulling all the calls, then when it displays them on the page, they are not always in order. I would like to be able to simply click the column header and have the whole table resort itself based on the header like in Excel. If that's not possible, maybe just having everything sort by Date correctly would work fine. Any body want to take a stab at it for me? <html><head> <link href="style.css" rel="stylesheet" type="text/css"> <link href="Scripts/EnterSubmit.js" rel="javascript" type="text/javascript"> <script type="text/javascript" src="ddtabmenufiles/ddtabmenu.js"> /*********************************************** * DD Tab Menu script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ //DD Tab Menu- Last updated April 27th, 07: http://www.dynamicdrive.com //Only 1 configuration variable below var ddtabmenu={ disabletablinks: false, ////Disable hyperlinks in 1st level tabs with sub contents (true or false)? currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/) definemenu:function(tabid, dselected){ this[tabid+"-menuitems"]=null this.addEvent(window, function(){ddtabmenu.init(tabid, dselected)}, "load") }, showsubmenu:function(tabid, targetitem){ var menuitems=this[tabid+"-menuitems"] for (i=0; i<menuitems.length; i++){ menuitems[i].className="" if (typeof menuitems[i].hasSubContent!="undefined") document.getElementById(menuitems[i].getAttribute("rel")).style.display="none" } targetitem.className="current" if (typeof targetitem.hasSubContent!="undefined") document.getElementById(targetitem.getAttribute("rel")).style.display="block" }, isSelected:function(menuurl){ var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "") return (ddtabmenu.currentpageurl==menuurl) }, addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload) var tasktype=(window.addEventListener)? tasktype : "on"+tasktype if (target.addEventListener) target.addEventListener(tasktype, functionref, false) else if (target.attachEvent) target.attachEvent(tasktype, functionref) }, init:function(tabid, dselected){ var menuitems=document.getElementById(tabid).getElementsByTagName("a") this[tabid+"-menuitems"]=menuitems for (var x=0; x<menuitems.length; x++){ if (menuitems[x].getAttribute("rel")){ this[tabid+"-menuitems"][x].hasSubContent=true if (ddtabmenu.disabletablinks) menuitems[x].onclick=function(){return false} } else //for items without a submenu, add onMouseout effect menuitems[x].onmouseout=function(){this.className=""} menuitems[x].onmouseover=function(){ddtabmenu.showsubmenu(tabid, this)} if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[x].href)){ ddtabmenu.showsubmenu(tabid, menuitems[x]) var setalready=true } else if (parseInt(dselected)==x) ddtabmenu.showsubmenu(tabid, menuitems[x]) } } } //SYNTAX: ddtabmenu.definemenu("tab_menu_id", integer OR "auto") ddtabmenu.definemenu("ddtabs1", 0) //initialize Tab Menu with ID "ddtabs1" and select 1st tab by default </script> <style type="text/css"> <!-- .style2 { font-size: 16px; font-style: italic; color: #00FF00; } --> </style> <body> <div id="ddtabs1" class="basictab"> <ul> <li><a href="DailyCallTotals_SelectDate.php" rel="sc2">Calls By Team</a></li> <li><a href="CallsByHour.php" rel="sc2">Calls By Hour</a></li> <li class="style2"><a href="AllCalls.php" rel="sc1">All Calls By Extension</a></li> </ul> </div> <h2>Show All Calls by Extension</h2> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> <div align="left">Enter Date: <input type="text" name="id" value="<?php echo date("m/d/y");?>"> <br> Enter Ext: <input type="text" name="ex" value=""> <br> <input type="submit" name="submit" value="Submit" onKeyPress="return submitenter(this,event)"> </div> </form> <?php //require_once('odbc.php'); // //$query = odbc_exec($odbc, "SELECT Top 1 * FROM AllInfo WHERE IO = 'Out' AND CO = '54' ORDER BY [DateTime] DESC, [Extension] DESC") or die (odbc_errormsg()); //while($row = odbc_fetch_array($query)) //{ // echo 'Database current as of<strong> '.date("F j, Y, g:i a", strtotime($row['DateTime'])).'</strong> and will update every 23 minutes.'; //} //odbc_close($odbc); //?> <hr> <p><?php require_once('odbc.php'); // Transform minutes like "105" into hours like "1:45". function minutesToHours ($sec, $padHours = false) { // holds formatted string $hms = ""; // there are 3600 seconds in an hour, so if we // divide total seconds by 3600 and throw away // the remainder, we've got the number of hours $hours = intval(intval($sec) / 3600); // add to $hms, with a leading 0 if asked for $hms .= ($padHours) ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':' : $hours. ':'; // dividing the total seconds by 60 will give us // the number of minutes, but we're interested in // minutes past the hour: to get that, we need to // divide by 60 again and keep the remainder $minutes = intval(($sec / 60) % 60); // then add to $hms (with a leading 0 if needed) $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':'; // seconds are simple - just divide the total // seconds by 60 and keep the remainder $seconds = intval($sec % 60); // add to $hms, again with a leading 0 if needed $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT); // done! return $hms; } if(isset($_POST['submit'])) { $id = $_POST['id']; $ex = $_POST['ex']; if($id!="" & $ex!="") { echo "<b>Total number of calls for : ".$id."<br></b>"; $unixtime = time(); echo "" . date("F j, Y, g:i a",$unixtime) . "<br><br>"; $sql = "SELECT Count(*) AS TotalNumberOfCalls FROM AllInfo WHERE Extension = '$ex' AND Date=#".$id."#"; $time = "SELECT Date, Extension, sum(DurationS) AS CountOfDuration FROM AllInfo WHERE Extension = '$ex' AND Date=#$id# GROUP BY Date, Extension"; $sql0 = "SELECT * FROM AllInfo WHERE Extension = '$ex' AND Date=#$id#"; $sql = odbc_exec($odbc,$sql) or die(odbc_errormsg()); $timequery = odbc_exec($odbc,$time) or die(odbc_errormsg()); $sql0 = odbc_exec($odbc,$sql0) or die(odbc_errormsg()); echo "<center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"borderTable\"><tr><th class=\"borderTable\"> Extension </th><th class=\"borderTable\"> Time </th><th class=\"borderTable\">Total Dials</th><th class=\"borderTable\">Total Talk Time</th></tr>"; while($row = odbc_fetch_array($sql)) { echo "<tr>"; echo "<td class=\"borderTable\"><center>$ex</center></td class=\"borderTable\">"; echo "<td class=\"borderTable\"><center>00:01-23:59</center></td class=\"borderTable\">"; echo "<td class=\"borderTable\"><center>".$row['TotalNumberOfCalls']."</center></td class=\"borderTable\">"; while($row = odbc_fetch_array($timequery)){ echo "<td class=\"borderTable\"><center>".minutesToHours($row["CountOfDuration"])."</center></td class=\"borderTable\"></table><p></p>"; } } // end while echo "<center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"borderTable\"><tr><th class=\"borderTable\"> Extension </th><th class=\"borderTable\"> Time </th><th class=\"borderTable\">In/Out</th><th class=\"borderTable\">Phone Number</th><th class=\"borderTable\">Duration</th></tr>"; while($row = odbc_fetch_array($sql0)) { echo "<tr>"; echo '<td class=\"borderTable\"><center>'.$row['Extension'].'</center></td class=\"borderTable\">'; echo '<td><center>'.date("h:i", strtotime($row['DateTime'])).'</center></td>'; echo '<td class=\"borderTable\"><center>'.$row['IO'].'</center></td class=\"borderTable\">'; echo '<td class=\"borderTable\"><center>('.$row['AC'].') '; echo ''.$row['PhN'].'</center></td class=\"borderTable\">'; echo '<td class=\"borderTable\"><center>'.$row['Duration'].'</center></td class=\"borderTable\">'; } // end while } // end if } // end if ?> <?php odbc_close($odbc); ?> </p> <p> </p> </body></html> Quote Link to comment Share on other sites More sharing options...
wellscam Posted September 22, 2008 Author Share Posted September 22, 2008 Just incase anyone wants to know, this is the resolution for this: $sql0 = "SELECT * FROM AllInfo WHERE Extension = '$ex' AND Date=#$id# ORDER BY Date DESC, Val(Left(Time,2)), Val(Right(Time,2))"; This will bunch together the am and pm times that are in the same hour but we only have data for 12 hours out of a day anyway, it's all right! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.