Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Old 08-14-2007, 03:20 PM IF NOT querystring
Novice Talker

Posts: 9
Trades: 0
I have a question on using querystrings. Is there some way to set a default value that is used when NO querystring is added to the URL?

I have a page that displays product information in a table form. I decided to make an option for the user to sort the data, so I created a variable which changes the SORT clause in the SQL statement. The variable is controlled using a querystring. So for example, "products.asp?sort=price" would sort products by price instead of model. This part works fine.

Here's where I need some help... When I initially load the page, I do not want the querystring added to the URL. I basically want to just load "products.asp" and have a default sort order. I assume I need something like "if not querystring", but I don't know if it's possible to use the presence of a querystring as an IF condition.

I'm looking for some suggestions. Any help is appreciated.
jfdt is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-14-2007, 03:28 PM Re: IF NOT querystring
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Code:
Sort_Order = "your default sort order"
If Request.QueryString ("sortorder") <> "" then
     Sort_Order = Request.QueryString ("sortorder")
     ' your sort order querystring instructions here.
end if
That oughta get you started.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 08-14-2007, 03:59 PM Re: IF NOT querystring
Novice Talker

Posts: 9
Trades: 0
Thanks, this gave me a start... Now I have a new question.

If I sort by price, "$1000" will be listed before "$100". Is there any way to control this? I do not want preceding 0's added to all my prices. There are multiple prices which range from hundreds to thousands, so setting ASC or DESC won't make a difference.
jfdt is offline
Reply With Quote
View Public Profile
 
Old 08-14-2007, 04:33 PM Re: IF NOT querystring
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
You would better start a new thread for your question, rather than overloading this one.
Anyway, for that ( and depending of your DB), you will need to cast your column type from string to number.

It depends of your db, so check you documentation, but once you do the cast to numeric, and strip every non numeric character, an ASC or DESC sort order will do the trick.

I just checked in mysql5, and this DB does the cast itself, it seems:
Code:
mysql> create table sandbox( txt varchar(20) );
Query OK, 0 rows affected (0.02 sec)

mysql> insert into sandbox values ('100$');
Query OK, 1 row affected (0.00 sec)

mysql> insert into sandbox values ('1000$');
Query OK, 1 row affected (0.00 sec)

mysql> insert into sandbox values ('1050$');
Query OK, 1 row affected (0.00 sec)

mysql> select * from sandbox order by txt desc;
+-------+
| txt   |
+-------+
| 1050$ |
| 1000$ |
| 100$  |
+-------+
3 rows in set (0.00 sec)

mysql>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-14-2007, 04:40 PM Re: IF NOT querystring
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by jfdt View Post
Thanks, this gave me a start... Now I have a new question.

If I sort by price, "$1000" will be listed before "$100". Is there any way to control this? I do not want preceding 0's added to all my prices. There are multiple prices which range from hundreds to thousands, so setting ASC or DESC won't make a difference.
As text, 9 is greater/more than 10. As integer or any numeric value, though, that's just plain wrong.

Chop off the $ and then force an integer or a floating point type conversion.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to IF NOT querystring
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15322 seconds with 12 queries