Ok I am going to try to make this question as clear as I can. We just recently started using Drupal and a third party built out part of our site for us. We have a views file which queries our Mysql database and pulls the courses from the table that match a particular search criteria. For example all Fall 2014 classes. They have it ordered by CID or Course ID. The Views page includes the Schedules results PHP page which then renders the information into a table. We want to be able to have sortable columns in the table. I have tried adding a jscript file which will do this without reloading the table info but it hasn't worked and I am not sure why. I have tried using the Drupal_add_js as well as just inserting the JS inline. I have also tried doing the href='/shedules?orderby=cname" but that doesn't seem to keep the data from the query from the views page. I am getting highly frustrated with this and I don't know where else to look. Any guidance you can give me would be greatly appreciated!
here is the views page
<!--
<pre>
<? print_r($_POST); ?>
</pre>
-->
<?php
$query = " SELECT * FROM ";
$semester = $_POST['semester'];
if(empty($_POST['text'])){
if($_POST['currentcourse'] == "1"){
$query .= " $semester WHERE (sdate <= NOW() OR sdate is NULL)";
} else {
$query .= " $semester WHERE (1=1)";
}
} else {
//$query .= " $semester WHERE (1=1)";
$query .= " $semester WHERE (sdate >= NOW() OR sdate is NULL)";
}
if( isset( $_POST['online'] ) && 'ON' == $_POST['online'] )
$query .= " AND ( `method`='WEB' OR `method`='Online' ) ";
if( isset( $_POST['text'] ) && !empty( $_POST['text'] ) ){
$words = explode(' ', urldecode( $_POST['text'] ) );
$fields = array( 'division', 'cid', 'cname', 'instructor' );
if( count($words) > 1){
// multi word search
$q = array();
foreach( $words as $w ){
$part = array();
foreach( $fields as $f ){
$part[] = " $f LIKE '%$w%' ";
}
$q[] = $part;
}
$final_parts = array();
foreach( $q as $query_part )
$final_parts[] = implode( ' OR ', $query_part);
$final_query = ' AND (' . implode(') AND (', $final_parts) . ')';
}else{
// single word search
$part = array();
foreach( $fields as $f ){
$part[] = " $f LIKE '%$_POST[text]%' ";
}
$final_query = ' AND ('.implode( ' OR ', $part).')';
}
$query .= " " . $final_query . " ";
}
if( isset( $_POST['area_id'] ) && '-1' != $_POST['area_id'] )
$query .= " AND cid LIKE '" . $_POST['area_id'] . "%'";
if( isset( $_POST['division_id'] ) && '-1' != $_POST['division_id'] )
$query .= " AND division = '" . $_POST['division_id'] . "'";
if( isset( $_POST['duration'] ) && '-1' != $_POST['duration'] )
$query .= " AND duration_min " . ( ( $_POST['durcomp'] == 'more' ) ? ' >= ' : ' <= ' ) . $_POST['duration'] . " ";
$query .= " AND ( 1=1 ";
if( isset($_POST['time']) && isset($_POST['time'][0]) && !empty($_POST['time'][0]) ){
$start_parts = explode(' ', $_POST['time'][0]);
$start_time = ((int)$start_parts[0] * 60) + (int)$start_parts[1];
$query .= " AND stime_min >= $start_time ";
}
if( isset($_POST['time']) && isset($_POST['time'][1]) && !empty($_POST['time'][1]) ){
$end_parts = explode(' ', $_POST['time'][1]);
$end_time = ((int)$end_parts[0] * 60) + (int)$end_parts[1];
$query .= "AND etime_min <= $end_time ";
}
$query .= " ) ";
$query .= " AND ( 1=1 ";
if( isset( $_POST['T'] ) && 'ON' == $_POST['T'] )
$query .= ( $_POST['dayop'] == 'AND' ) ? ' AND ' : ' OR ' . " day_T = 1 ";
if( isset( $_POST['W'] ) && 'ON' == $_POST['W'] )
$query .= ( $_POST['dayop'] == 'AND' ) ? ' AND ' : ' OR ' . " day_W = 1 ";
if( isset( $_POST['R'] ) && 'ON' == $_POST['R'] )
$query .= ( $_POST['dayop'] == 'AND' ) ? ' AND ' : ' OR ' . " day_R = 1 ";
if( isset( $_POST['F'] ) && 'ON' == $_POST['F'] )
$query .= ( $_POST['dayop'] == 'AND' ) ? ' AND ' : ' OR ' . " day_F = 1 ";
if( isset( $_POST['S'] ) && 'ON' == $_POST['S'] )
$query .= ( $_POST['dayop'] == 'AND' ) ? ' AND ' : ' OR ' . " day_S = 1 ";
$query .= " ) ORDER BY cid";
/* echo $query; */
$string_query = $query;
$query = db_query($query);
$result = $query->fetchAll();
$in_progress = 0;
foreach ($result as $r) {
if (!empty($r->sdate) && strtotime($r->sdate) < time()) {
$in_progress++;
}
}
endif; ?>
<?php
require( __dir__ . '/course-schedule-headings-table.php');
?>
<?php
require( __dir__ . '/course-schedule-results.php');
?>
And here is the Results page that is included
<?php $now = time();?>
<table id="scheduletable" style="width:450px; font-size :10px;">
<thead>
<tr valign="top">
<th scope="col" bgcolor="#FFFFCC"><a href="/schedules?sort=cid">Course ID</a><br></th>
<th scope="col" bgcolor="#E0E0E0" style="width: 12px"><a href="/schedules?sort=cname">Course name</a> </th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=credits">Credits</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=method">Type</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=sdate">Start date</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=edate">End date</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=days">Days</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=stime">Start time</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=etime">End time</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=instructor">Instructor</a></th>
</tr>
</thead>
<?php foreach($result as $course): ?>
<?php
$color="#FFFFFF";
if( !empty($course->sdate) && strtotime($course->sdate) < $now )
$color = $color_in_progress;
if( "Online" == trim( $course->method ) )
$color = $color_online;
if( "Hybrid" == trim( $course->method ) )
$color = $color_hybrid;
if( !empty($course->stime_min) && $course->stime_min >= 960 )
$color = $color_evening;
?>
<tbody>
<tr>
<tr bgcolor="<?=$color?>">
<td align="center">
<a href="/courses/?id=<?= $course->cid ?>">
<?= $course->cid ?>
</a>
</td>
<td class="name" style="width: 1.5">
<?= $course->cname ?>
</td>
<td class="small" align="center">
<?= $course->credits ?>
<?= ("COMP100 CE0" == $course->cid) ? '.50' : null?>
</td>
<td align="center">
<?= $course->type?>
</td>
<td align="center">
<?= date( "m/d", strtotime( $course->sdate ) )?>
</td>
<td align="center">
<?= date( "m/d", strtotime( $course->edate ) )?>
</td>
<td align="center">
<?= $course->days ?>
</td>
<td align="center">
<?= date( "h:i", strtotime( $course->stime ) )?>
</td>
<td align="center">
<?= date( "h:i", strtotime( $course->etime ) )?>
</td>
<td align="center">
<?= $course->instructor ?>
</td>
</tr>
</tbody>
<? endforeach; ?>
</table>
Here is the table output example: The styling is done dynamically based on queried results this is from the view source after executing a search.
<table id="scheduletable" style="width:450px; font-size :10px;">
<thead>
<tr valign="top">
<th scope="col" bgcolor="#FFFFCC"><a href="/schedules?sort=cid">Course ID</a><br></th>
<th scope="col" bgcolor="#E0E0E0" style="width: 12px"><a href="/schedules?sort=cname">Course name</a> </th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=credits">Credits</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=method">Type</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=sdate">Start date</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=edate">End date</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=days">Days</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=stime">Start time</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=etime">End time</a></th>
<th scope="col" bgcolor="#E0E0E0"><a href="/schedules?sort=instructor">Instructor</a></th>
</tr>
</thead>
<tbody>
<tr>
<tr bgcolor="#FFCCCC">
<td align="center">
<a href="/courses/?id=ABED003 11">
ABED003 11 </a>
</td>
<td class="name" style="width: 1.5">
Basic Education </td>
<td class="small" align="center">
6 </td>
<td align="center">
</td>
<td align="center">
08/18 </td>
<td align="center">
10/10 </td>
<td align="center">
MTWTHF </td>
<td align="center">
08:30 </td>
<td align="center">
10:50 </td>
<td align="center">
Melissa Escamilla </td>
</tr>
</tbody>