Jump to content


Photo

How To Sort Columns with Hyperlinks


  • Please log in to reply
3 replies to this topic

#1 phpBeginner06

phpBeginner06
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 15 October 2006 - 08:02 PM

Is there any way to sort a data table column that has hyperlinks in it; in ascending order? I tried to use "ORDER BY make ASC" (where "make" was the name of the column). The results where that the text in column is not being sorted by ascending; but the hyperlinks tag's text is being sorted by ascending. How can I make the text sort by ascending and exlude the hyperlink tag's text from being sorted by ascending?

#2 MCP

MCP
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 16 October 2006 - 12:13 AM

assuming your links are like this:

<a href="http://www.google.com">Google</a>

then you can use a combination of charindex and substr to first locate the position of the first ">" (I don't think that ">" is a valid URL character), and the take everything after that and sort on that. You wouldn't need to strip the "</a>", since it's pretty will immaterial (at the end and always the same).

so something like:

order by substr(make,charindex(">",make),len(make))  -- this is untested and from memory, and most assuredly syntactically wrong

#3 phpBeginner06

phpBeginner06
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 16 October 2006 - 07:27 AM

Thanks for the quick reply MCP.

I found a way to accomplish what I was trying to do. I added two new data table columns; the first contains the opening hyperlink's tag:
<a href="http://www.google.com">
and the second contains the closing hyperlink's tag:
</a>
I gave the columns a instance/variable name of "openLink" (for the opening of hyperlink's tag) and "closeLink" (for the closing of hyperlink's tag). Then in my HTML/PHP, I used an echo to display all three instance/variable names.

Example: echo "$openLink $make $closeLink"; //  this creates the hyperlink

This may not be the correct way to do this; but it worked great for me. Now all the text in my data table's column sorts in ascending order and the hyperlink tag's text is now excluded from the sorting process.

#4 argoSquirrel

argoSquirrel
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 16 October 2006 - 04:32 PM

Correct me if I am of base, but couldn't you just store the hyperlink itself?  I see no need to store <a href=" on every single one when you could just echo it from php.  That should solve the sort and clean up a little redundancy.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users