473,805 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making dynamic table sortable

I'm doing a small project right now where I create a table from a
database. This is the code, which Dreamweaver, for the most part,
has written:

***

<?php
mysql_select_db ($database_tdre am, $tdream);
$query_rstdream = "SELECT * FROM albums ORDER BY `year` ASC";
$rstdream = mysql_query($qu ery_rstdream, $tdream) or die
(mysql_error()) ;
$row_rstdream = mysql_fetch_ass oc($rstdream);
$totalRows_rstd ream = mysql_num_rows( $rstdream);
?>

***

<table cellspacing="0" >
<thead>
<tr>
<td>Album</td>
<td>Year</td>
<td>Era</td>
<td>Type</td>
</tr>
</thead>
<tbody>
<?php do { ?>
<?php
$class = ($class == 'odd') ? 'even' : 'odd';
?>
<tr class="<?php echo $class ?>">
<td><?php echo $row_rstdream['Name']; ?></td>
<td><?php echo $row_rstdream['Year']; ?></td>
<td><?php echo $row_rstdream['Era']; ?></td>
<td><?php echo $row_rstdream['Type']; ?></td>
</tr>
<?php } while ($row_rstdream = mysql_fetch_ass oc($rstdream));
?>
</tbody>
</table>

***

Sorry for the length of the examples. I have a basic
understanding of what the code is doing, so I should be able to
modify it if I knew I was heading in the right direction. My
object is to make this table sortable, by clicking on the column
headers. I have an additional column in my database table which
is an auto_increment counter. Would anyone have some ideas or
code that could help me figure this out? I'm not sure how to
approach it, and was hoping that there was a simple answer to the
problem.

TIA
Ian
--
http://www.bookstacks.org/
Jul 17 '05
34 7661
In comp.lang.php Geoff Berrow wrote:
Add (at the top)

$order=$_GET['order'];


Woo-hoo! Thank you, that worked just fine. Now I think I've finally
got this part of the page done.

--
Ian

http://www.bookstacks.org/
Jul 17 '05 #31
I dunno whetrher you've considered this and rejected it, but there're a
number of free client-side JS scrpts that do the sort, alternating
directions too, completely client-side, and handling strings, numerics,
dates.

Google for "sorttable. js" . I'm using it for 150-row datasets, and
getting nice performance on a dinky machine in a number of app's.
Piece of cake!

Jul 17 '05 #32
In comp.lang.php Positive Contrarian wrote:
Google for "sorttable. js" .


That's what I was using before, actually. I want to make
everything PHP now, as that's what I'm learning. Also, the JS
sort table didn't do secondary sorts. For instance, in this table
there are a number of times when more than one album comes out in
the same year. In order to get the JS to sort correctly, I would
add little sort characters, like "a" "b" "c" etc., to the title
and make it invisible through display: none. At least with the
PHP that's done for me, since I enter them into the database in
order, and can sort by both, say, "Year" and "ID".

If you're using zebra rows in your JS sort table, you might try
using the PHP line that I found somewhere and added in:

<?php
$class = ($class == 'odd') ? 'even' : 'odd';
?>
<tr class="<?php echo $class ?>">

then all you need is the CSS class for .even and you're set.

Ian
--
http://www.bookstacks.org/
Jul 17 '05 #33
Have a look at
http://www.tonymarston.co.uk/php-mys...faq.html#faq07 to see
how I have implemented column sorting without using javascript.

--
Tony Marston

http://www.tonymarston.net
"Ian Rastall" <id*******@gmai l.com> wrote in message
news:Xn******** *************** ****@130.133.1. 4...
In comp.lang.php Positive Contrarian wrote:
Google for "sorttable. js" .


That's what I was using before, actually. I want to make
everything PHP now, as that's what I'm learning. Also, the JS
sort table didn't do secondary sorts. For instance, in this table
there are a number of times when more than one album comes out in
the same year. In order to get the JS to sort correctly, I would
add little sort characters, like "a" "b" "c" etc., to the title
and make it invisible through display: none. At least with the
PHP that's done for me, since I enter them into the database in
order, and can sort by both, say, "Year" and "ID".

If you're using zebra rows in your JS sort table, you might try
using the PHP line that I found somewhere and added in:

<?php
$class = ($class == 'odd') ? 'even' : 'odd';
?>
<tr class="<?php echo $class ?>">

then all you need is the CSS class for .even and you're set.

Ian
--
http://www.bookstacks.org/

Jul 17 '05 #34
I noticed that Message-ID: <Xn************ *************** @130.133.1.4>
from Ian Rastall contained the following:
If you're using zebra rows in your JS sort table, you might try
using the PHP line that I found somewhere and added in:

<?php
$class = ($class == 'odd') ? 'even' : 'odd';


Ahh... I'd spotted that and didn't think it looked like Dreamweaver
generated code. Nice.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #35

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3311
by: jeffsal | last post by:
I am using sorttable.js to sort a table which works fine which allows a user to sort the table by clicking on the column header. Is there some code I could add to the page (onload or something) to auto sort by the first column without user clicking on it. Here is the sorttable.js code. addEvent(window, "load", sortables_init); var SORT_COLUMN_INDEX;
1
1654
by: Ross | last post by:
The following codes originally provided by a kind responder Toby A Inkster in another newsgroup for working on displaying a table on web capable of sorting are modified by me (a newbie). How to disable sorting by say, length and chart (last few codes at the end)? I find the order is important to display so cannot just single them out. <?php function insert_datatable_cmp ($a, $b) { return ($a]<$b]) ? -1 : 1; }
1
2651
by: cotton_gear | last post by:
Hello, Fiest of all let me thank this group for so quick in responding to any postings. I am using a javascript based utility from a site to sort the columns of the table. But, for some strange reason it is not working on colmuns containg checkboxes, text-boxes (or, any user input fileds). For checkbox column, the values are lost when clicked on the column title to sort. I tried a lot to modify but couldnt achive what I wanted.
1
2070
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured query language, which forces me to do the join manually via arrays. Right now, I'm having trouble getting these query results (which are in
7
4830
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the expandable row, the hidden row is made visible with css. The problem is when i sort the rows, the hidden rows get sorted as well which i don't want and want to be moved (while sorting) relative to their parent rows. The following is my complete html code...
1
16983
by: since | last post by:
I figured I would post my solution to the following. Resizable column tables. Search and replace values in a table. (IE only) Scrollable tables. Sortable tables. It is based on a lot examples I found on the web. Works in IE and mozilla. http://www.imaputz.com/cssStuff/bigFourVersion.html
5
4200
by: Stepheno | last post by:
Hi, I am a recently converted Iseries (AS/400) RPG programmer trying to learn HTML/CSS/JavsScript all at the same time (not fun). My problem deals mostly with CSS. I will be reveiving a table, for which number of rows/columns i will not know, and I have to pretty up the table, including a verical scroll bar. This has to work in IE6, IE7, and FireFox 3.5. The CSS I currently have will give me a scrollable table, but only if I hard code...
5
4962
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10369
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.