Jump to content

How To Sort Columns with Hyperlinks


phpBeginner06

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/24018-how-to-sort-columns-with-hyperlinks/
Share on other sites

assuming your links are like this:

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

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
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: [code]<a href="http://www.google.com">[/code] and the second contains the closing hyperlink's tag: [code]</a>[/code] 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.