YOU ROCK!!!!!!! I have been wrestling with this for 3 weeks!!!!!! If you could add in the date part I would appreciate it!!!!!! THANK YOU THANK YOU THANK YOU!!!!!
Main Topics
Browse All TopicsI have a page in PHP which displays a SQL query output into an HTML table. What I need to accomplish is making the table sort-able by clicking on the headers (i.e. one click sorts acesnding, second click sorts decending..etc.)
I am new to PHP and have been told that possibly the best way would be to write a multi dimensional array.
Here is an example of the query and table section of my code...again I am new to PHP so excuse any "mistakes":
<div id="centercontent">
<TABLE border="1" width="800" height="0" bordercolorlight="#fff" align="left"
bordercolordark="#black" bordercolor="#006666">
<TH width="110"><span title="Date of Occurence">Date</br>dd/mm/
<TH width="70"><span title="Location Number">Location</span></T
<TH width="70"><span title="Sum of CRC+Frame+Abort+Giants+Run
<TH width="70"><span title="BECNs Received by Remote">Remote BECNs</span></TH>
<TH width="80"><span title="Frame Delivery Rate to the Head End">FDR-HE</span></TH>
<TH width="80"><span title="Frame Delivery Rate to the Remote End">FDR-RE</span></TH>
<TH width="40"><span title="Frame Delivery Rate Objective">FDR</span></TH>
<TH width="80"><span title="Data Delivery Rate to the Head End">DDR-HE</span></TH>
<TH width="80"><span title="Data Delivery Rate to the Remote End">DDR-RE</span></TH>
<TH width="40"><span title="Data Delivery Rate Objective">DDR</span></TH>
<TH width="80"><span title="Daily Score=Frame Delivery Rate Objective+Data Delivery Rate Objective/2">Daily Score</span></TH></TABLE>
</div>
<br />
<br />
<br />
<?
if (!(isset($day)))
{
$day = 1;
}
$db = &new MSSQL($dbi['host'], $dbi['user'], $dbi['pass'], $dbi['database']);
$FDRHE='[FDRtoHE]';
$FDRRE='[FDRtoRE]';
$DDRHE='[DDRtoHE]';
$DDRRE='[DDRtoRE]';
$DDR='[DDRtoHE]+[DDRtoRE]'
$FDR='[DDRtoHE]+[DDRtoRE]'
$sql = "Select
mm,dd,yyyy,Location,
AVG(RmtPri+PriSec) AS SysTimeDelta,
PhysicalErrors,BECNsFromRe
FDRtoHE, FDRtoRE, DDRtoHE, DDRtoRE,
Round((((SUM($FDRHE+$FDRRE
Round((((SUM($DDRHE+$DDRRE
Round((((SUM($DDR+$FDR)/2)
From ##mytemptable
Group By mm,dd,yyyy,Location,Physic
Order By mm,dd,yyyy,DailyScore,Loca
$result = $db->query($sql);
?>
<div id="centercontent" style=" width:820px; height:500px; overflow:auto;">
<?
echo "<TABLE style='text-decoration:non
bordercolordark='#black' bordercolor='#006666' >";
while ($row = $result->fetch())
{
echo "<TR>";
echo "<TD width='25'align='center'>"
echo "<TD width='25'align='center'>"
echo "<TD width='25'align='center'>"
echo "<TD width='80'align='center'>"
echo "<TD width='80'align='center'>"
echo "<TD width='80'align='center'>"
echo "<TD width='80'align='center'>"
echo "<TD width='80'align='center'>"
echo "<TD width='42'align='center'>"
echo "<TD width='80'align='center'>"
echo "<TD width='80'align='center'>"
echo "<TD width='40'align='center'>"
echo "<TD width='80'align='center'>"
echo "</TR>";
}
echo "</TABLE>";
?>
</div>
</body>
</HTML>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> THANK YOU THANK YOU THANK YOU!!!!!
My Pleasure :=)
>> If you could add in the date part I would appreciate it!!!!
Order by DATE format is somewhat trickier in your case. (I think you have different fields for Month, Day and Year..) I dont know why you have in such format while there are numerous enough funcitons that can be dont with DATE or DATETIME data-types.
However which version of MySql you are using ? Can you run this Query in your PhpMyAdmin or SQL command and tell me if it works or not.
SELECT CONCAT_WS('-', mm, dd, yyyy) as MyDate FROM `test` ORDER BY STR_TO_DATE(CONCAT_WS('-',
>> .IS there a way to "highlight or bold" the column which it is currently sorted by?
See the changes :
// .......
// .......
$order_query = " ORDER BY mm,dd,yyyy,DailyScore,Loca
if( isset($_GET["orderBy"]) && !empty($_GET["orderBy"]) ) {
$orderByVal = ($_GET["orderBy"] < 13) ? $_GET["orderBy"] : 1; // ADDED THIS LINE
switch ($_GET["orderBy"]) {
// .......
// .......
And change your table as :
<TABLE border="1" width="800" height="0" bordercolorlight="#fff" align="left" bordercolordark="#black" bordercolor="#006666">
<TH width="110"><span title="Date of Occurence"><? if($orderByVal==1) echo "<b>"; ?> Date<br/>dd/mm/yyyy<? if($orderByVal==1) echo "</b>"; ?> </span></TH>
<TH width="70"><span title="Location Number"><? if($orderByVal==2) echo "<b>"; ?> <a href="this_page.php?orderB
<TH width="70"><span title="Sum of CRC+Frame+Abort+Giants+Run
<? if($orderByVal==3) echo "<b>"; ?> <a href="this_page.php?orderB
</TH>
<TH width="70"><span title="BECNs Received by Remote"><? if($orderByVal==4) echo "<b>"; ?> <a href="this_page.php?orderB
<TH width="80"><span title="Frame Delivery Rate to the Head End"><? if($orderByVal==5) echo "<b>"; ?> <a href="this_page.php?orderB
<TH width="80"><span title="Frame Delivery Rate to the Remote End"><? if($orderByVal==6) echo "<b>"; ?> <a href="this_page.php?orderB
<!-- and so on... -->
</TABLE>
Hope you understand.
Thank you again.
For the date portion: I am using SQL 2000, so the line you sent does not work. But after reveiw, I do not need the abillity to sort by date after all.
As for the highlighting or bolding a column header when it is the sort identifier, I placed the code you sent into my test page, and do not see a difference from what it was doing before. Thanks.
Business Accounts
Answer for Membership
by: ldbkuttyPosted on 2005-01-31 at 07:56:44ID: 13183668
Not sure why you want to use Multi-dimensional Array...Do you mean you want to sort the results based on more than one Column... ?
tion $sort";
tion $sort";
yyyy</span ></TH> y=2&sort=< ?=$sort?>" >Location< /a></span> </TH> ts @ Remote"> y=3&sort=< ?=$sort?>" >Physical Errors</a></span> y=4&sort=< ?=$sort?>" >Remote </a>BECNs</span></TH> y=5&sort=< ?=$sort?>" >FDR-HE</a ></span></ TH> y=6&sort=< ?=$sort?>" >FDR-RE</a ></span></ TH> y=7&sort=< ?=$sort?>" >FDR</a></ span></TH> y=8&sort=< ?=$sort?>" >DDR-HE</a ></span></ TH> y=9&sort=< ?=$sort?>" >DDR-RE</a ></span></ TH> y=10&sort= <?=$sort?> ">DDR</a>< /span></TH > y=11&sort= <?=$sort?> ">Daily Score</a></span>
mote, )/2))/Coun t (*)),2) AS FDR, )/2))/Coun t (*)),2) AS DDR, )/2),2)AS DailyScore alErrors,B ECNsFromRe mote,RmtPr i,PriSec,F DRtoHE, FDRtoRE, DDRtoHE, DDRtoRE " . $order_query;
This is a general approach that will sort in ASC/DESC order for every single table column.
<?php
$sort = "DESC";
if(isset($_GET["sort"]) && !empty($_GET["sort"])) {
$sort = ($_GET["sort"]=="ASC") ? "DESC" : "ASC";
}
$order_query = " ORDER BY mm,dd,yyyy,DailyScore,Loca
if( isset($_GET["orderBy"]) && !empty($_GET["orderBy"]) ) {
switch ($_GET["orderBy"]) {
case 2:
$order_query = " ORDER BY Location $sort";
break;
case 3:
$order_query = " ORDER BY PhysicalErrors $sort";
break;
case 4:
$order_query = " ORDER BY BECNsFromRemote $sort";
break;
case 5:
$order_query = " ORDER BY FDRtoHE $sort";
break;
case 6:
$order_query = " ORDER BY FDRtoRE $sort";
break;
case 7:
$order_query = " ORDER BY FDR $sort";
break;
case 8:
$order_query = " ORDER BY DDRtoHE $sort";
break;
case 9:
$order_query = " ORDER BY DDRtoRE $sort";
break;
case 10:
$order_query = " ORDER BY DDR $sort";
break;
case 11:
$order_query = " ORDER BY DailyScore $sort";
break;
default:
$order_query = " ORDER BY mm,dd,yyyy,DailyScore,Loca
break;
}
}
?>
<TABLE border="1" width="800" height="0" bordercolorlight="#fff" align="left" bordercolordark="#black" bordercolor="#006666">
<TH width="110"><span title="Date of Occurence">Date</br>dd/mm/
<TH width="70"><span title="Location Number"><a href="this_page.php?orderB
<TH width="70"><span title="Sum of CRC+Frame+Abort+Giants+Run
<a href="this_page.php?orderB
</TH>
<TH width="70"><span title="BECNs Received by Remote"><a href="this_page.php?orderB
<TH width="80"><span title="Frame Delivery Rate to the Head End"><a href="this_page.php?orderB
<TH width="80"><span title="Frame Delivery Rate to the Remote End"><a href="this_page.php?orderB
<TH width="40"><span title="Frame Delivery Rate Objective"><a href="this_page.php?orderB
<TH width="80"><span title="Data Delivery Rate to the Head End"><a href="this_page.php?orderB
<TH width="80"><span title="Data Delivery Rate to the Remote End"><a href="this_page.php?orderB
<TH width="40"><span title="Data Delivery Rate Objective"><a href="this_page.php?orderB
<TH width="80"><span title="Daily Score=Frame Delivery Rate Objective+Data Delivery Rate Objective/2">
<a href="this_page.php?orderB
</TH>
</TABLE>
and change your query as :
$sql = "Select
mm,dd,yyyy,Location,
AVG(RmtPri+PriSec) AS SysTimeDelta,
PhysicalErrors,BECNsFromRe
FDRtoHE, FDRtoRE, DDRtoHE, DDRtoRE,
Round((((SUM($FDRHE+$FDRRE
Round((((SUM($DDRHE+$DDRRE
Round((((SUM($DDR+$FDR)/2)
From ##mytemptable
Group By mm,dd,yyyy,Location,Physic
// I left the first-date part for now. Tell me if this works and if it is, I'll modify the code for date ordering.