Jump to content

Prevention of data reloading using filter and sorting


Hephaestus

Recommended Posts

Hello,

Firstly, I' d like to apologize if I can't state my problem cleary (not so good in English). Anyway, here's the deal:

Currently I'm doing a simple project where products are stored in mysql table with their own ID. I want to display all that data in a html table. But the data must be sorttable and in a separate page, users should have the ability to select (via checkboxes) which columns to display. The filtering I've solved relatively easy, but ordering, only partially. So know I need little help. I'll explain the problem using my code:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php
// Column filter script, which is include only once, due to the reuse of it when a reload button is clicked.
include_once("filterscript.php");


//Here I have a sortting code. It's quite simple.
$default_sort = 'vid'; // Default sort order by first column

if (!isset ($_GET['order'])) // Checking for sort order
{ $order = $default_sort; }
else
{ $order = $_GET['order']; }


//No comments here :-)
include 'sqlconfig.php';
include 'sqlconnect.php';


//---Fetching and Displaying headings-------------------------------------------
$result = mysql_query("SELECT $filt FROM charts ORDER BY $order") or die (mysql_error());
$row = mysql_fetch_assoc($result);
?>

<table witdh="100%" border="0" cellpading="4" cellspacing="2">
<tr width="100%" bgcolor="#CCCCCC">
<?php
if (strstr($filt, vid))
{?>
<td><a href="<?php print $_SERVER['PHP_SELF']."?order=vid";?>">ID</a></td>
<?php
}
and etc...
[/quote]

Now, as you can see, I have a not so complex code. Everything is fine, when a user selects which columns to display, and everything is fine, even, when a reload button is clicked, but when the user clicks the header to sort, page reloads with all the columns, not the ones selected by user. It seems, that this click invokes the code to be read entirely from start. The "include_once" does not help here :( How can I write the code, that theclick will only do the reselection of data from table, while not starting from the beginning? And another of topic question: How to make data sort and ASC and DSC by clicking multiple times? :-)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.