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
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
Link to comment
Share on other sites

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