Jump to content

Recommended Posts

I have gone through some of the sort postings but I am still unable to get mine to work properly.  I imagine since I have been piecing my page together, I have not used a clear cut way of designing my page.  The issue is that I'm not a programmer and have limited knowledge of PHP.  I seem to be getting the basics but some of the more advanced issues seem to make my head spin.

 

I want to add four links at the top of my page that will allow the user to select which way they want to sort.

 

I was just going to start with one and then I would be able to duplicate as needed.

 

<td align="center">Sort by: <a href=\"<?php echo ".$_SERVER['PHP_SELF']."?sort=itc_tickets.ticket_status\?>">Status</a></td>

 

My select code is as follows:

$sort = (isset($_GET['sort'])) ? $_GET['sort'] : "itc_status_listing.status_level";

$query_asset_details="SELECT itc_tickets.ticket_nbr, itc_tickets.ticket_status, itc_tickets.ticket_category, itc_tickets.ticket_priority, itc_tickets.issued_by, itc_tickets.assigned_to, itc_tickets.lastupdt_date, itc_tickets.create_date, itc_tickets.description FROM itc_tickets, itc_priority_listing, itc_status_listing WHERE itc_tickets.ticket_status = 'closed' AND itc_tickets.ticket_priority = itc_priority_listing.priority_name AND itc_tickets.ticket_status = itc_status_listing.status_name ORDER BY $sort ASC, itc_priority_listing.priority_level ASC, itc_tickets.create_date DESC,  itc_tickets.ticket_nbr ASC LIMIT $recordstart, $pagesize";        
$result = mysql_query($query_asset_details) or die("Error: " . mysql_error()); 

 

Now I would think with the a href the user would click on the option and then the isset would allow for the order by to be altered to the desired sort option.

 

Of course my <a href is not working and I'm not sure how to add the php code to make it work.

 

Any help would be greatly appreciated.

 

 

A simple example.

 

<?php

  echo "Order by  <a href='?orderby=foo'>foo</a><br />";
  echo "Order by  <a href='?orderby=bar'>bar</a><br />";
  echo "Order by  <a href='?orderby=bob'>bob</a><br />";

  if (isset($_GET['orderby'])) {
    $valid = array('foo','bar','bob'); // valid fields.
    if (in_array($_GET['orderby'],$valid)) {
      $orderby = $_GET['orderby'];
    } else {
      $orderby = 'foo'; // default.
    }
  } else {
    $orderby = 'foo'; // default.
  }

  // as an example, i'll just echo our query.
  $sql = "SELECT * FROM table ORDER BY $orderby;";
  echo $sql;

?>

 

Hope this helps.

Actually, your problem may just be your link. Can we see the actual code that creates your links?

 

Yes, I have a page called Closed.php and within that page I have all the code for the links.  The only code is what I have shown.

 

<td align="center">Sort by: <a href=\"<?php echo ".$_SERVER['PHP_SELF']."?sort=itc_tickets.ticket_status?>">Status</a></td>

We got it!  Thanks for the help.  I figured there had to be a way to pass the value, I was just not sure how to pass it through.

 

  if (isset($_GET['orderby'])) {
    $valid = array('itc_tickets.ticket_priority','itc_tickets.ticket_status','itc_tickets.ticket_category','itc_tickets.lastupdt_date'); // valid fields.
    if (in_array($_GET['orderby'],$valid)) {
      $orderby = $_GET['orderby'];
    } else {
      $orderby = 'itc_status_listing.status_level'; // default.
    }
  } else {
    $orderby = 'itc_status_listing.status_level'; // default.
  }
$query_asset_details="SELECT itc_tickets.ticket_nbr, itc_tickets.ticket_status, itc_tickets.ticket_category, itc_tickets.ticket_priority, itc_tickets.issued_by, itc_tickets.assigned_to, itc_tickets.lastupdt_date, itc_tickets.create_date, itc_tickets.description FROM itc_tickets, itc_priority_listing, itc_status_listing WHERE itc_tickets.ticket_status = 'closed' AND itc_tickets.ticket_priority = itc_priority_listing.priority_name AND itc_tickets.ticket_status = itc_status_listing.status_name ORDER BY $orderby ASC, itc_priority_listing.priority_level ASC, itc_tickets.create_date DESC,  itc_tickets.ticket_nbr ASC LIMIT $recordstart, $pagesize";        
$result = mysql_query($query_asset_details) or die("Error: " . mysql_error()); 

 

And then here are the links.

 

<?php
  echo "Order by  <a href='?orderby=itc_tickets.ticket_priority'>Priority</a>  |";
  echo "Order by  <a href='?orderby=itc_tickets.ticket_category'>Category</a>  |";
  echo "Order by  <a href='?orderby=itc_tickets.lastupdt_date'>Last Updated</a>"; ?>

 

 

the page is a bit messy, but it works.

Thanks again!

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.