Book Image

jQuery 1.3 with PHP

Book Image

jQuery 1.3 with PHP

Overview of this book

To make PHP applications that respond quickly, avoid unnecessary page reloads, and provide great user interfaces, often requires complex JavaScript techniques and even then, if you get that far, they might not even work across different browsers! With jQuery, you can use one of the most popular JavaScript libraries, forget about cross-browser issues, and simplify the creation of very powerful and responsive interfaces ñ all with the minimum of code. This is the first book in the market that will ease the server-side PHP coder into the client-side world of the popular jQuery JavaScript library. This book will show you how to use jQuery to enhance your PHP applications, with many examples using jQuery's user interface library jQuery UI, and other examples using popular jQuery plugins. It will help you to add exciting user interface features to liven up your PHP applications without having to become a master of client-side JavaScript. This book will teach you how to use jQuery to create some really stunning effects, but without you needing to have in-depth knowledge of how jQuery works. It provides you with everything you need to build practical user interfaces for everything from graphics manipulation to drag-and-drop to data searching, and much more. The book also provides practical demonstrations of PHP and jQuery and explains those examples, rather than starting from how JavaScript works and how it is different from PHP. By the end of this book, you should be able to take any PHP application you have written, and transform it into a responsive, user-friendly interface, with capabilities you would not have dreamed of being able to achieve, all in just a few lines of JavaScript.
Table of Contents (16 chapters)
jQuery 1.3 with PHP
Credits
About the Author
About the Reviewers
Preface
Index

Sorting by column


In the URL string shown in the last section, there are a few parameters to do with sorting:

  • iSortingCols: This defines the number of columns that we are sorting. (We'll stick with just one for this chapter.)

  • iSortCol_0: This defines the first column to sort. The value is numerical, starting with 0, and corresponds to what columns are displayed in the table, not the fields in the database.

  • iSortDir_0: This defines the direction the column should be sorted in. Handily, this value is either asc or desc, which we can plug directly into the query.

To make use of the numerical nature of iSortCol_0, we will add an array of column names to get_data.php. Add it to the "initialize variables" block:

$cols=array('ccode','city','longitude','latitude');

And then, we will generate MySQL's order by clause's information by adding the following just below this line:

// { sort by 
$scol=0; 
if(isset($_REQUEST['iSortCol_0'])){ 
  $scol=(int)$_REQUEST['iSortCol_0']; 
  if($scol>3 || $scol...