Forums

This topic is locked

user choose order problem

Posted 04 Jul 2002 16:56:55
1
has voted
04 Jul 2002 16:56:55 Yael Korin posted:
Hoe can I let users choose the order of their request.
I did
order by 'varorder'

and then
in the variables place of the window:

var order | % | thedate

It´s not even working in the Test.

What´s wrong ??

Yae

Replies

Replied 04 Jul 2002 17:14:03
04 Jul 2002 17:14:03 aegis kleais replied:
Simple enough.

create a recordset called rcdUsers and click ADVANCED.

Click + 2 times to create 2 blank variables and then fill in the following information

MM_order | fldName | Request.QueryString("order"
MM_sort | ASC | Request.QueryString("sort"

Then at the top change the query string to

SELECT *
FROM tblUsers
ORDER BY MM_order MM_sort

--------------------------------

What you've done here is made a dynamic recordset. If no variables are passed, the defaults (sorting by fldName ASCendingly) will be used. Now you need to name links to the page you're working on. Ie, if the page you made is called page.asp, you can auto sort the recordset by making pages with the following link:

page.asp?order=fldName&sort=ASC
page.asp?order=fldName&sort=DESC
page.asp?order=fldDate&sort=ASC

When clicked on, they pass the order and sort info which is parsed on page load to create a dynamically ordered and sorted recordset.
Replied 04 Jul 2002 17:55:47
04 Jul 2002 17:55:47 Yael Korin replied:
still dont´s understand.
what I Want i to let the user select an option from a menu, like, order by date.
Then the recordset, wich has yet lots of lines, must order the querry, in this case, by date.
The default value doesn´t matter that much.

So I created the menu order, wich values of the names of the fiels, and then in the rs window, created the variable and defined it saying Request/¡("mnuorder"

I don´t understand what you posted, I did it but I cant´t apply it . I´m new <img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle> in this.

Yae
Replied 04 Jul 2002 19:24:45
04 Jul 2002 19:24:45 aegis kleais replied:
Maybe it's your train of thought that if off-track. Sometimes I get so focused on one method of work, that I don't see things from other angles.

Let me explain a bit more in full. First of all, you should have basic HTML and Javascript skills before attempting this. Without understanding of those, you'll always have a difficult time (Dreamweaver is a great program, but it can't do EVERYTHING for you)

But here's how the system works.

You are building a recordset (rs) which is a collection of data from a database depending on certain criteria. When building the rs, you must provide what's known as default and run-time values for, in this case, the sorting and ordering of the recordset. To do this, we make 2 variables (because variables can change) And set them with the following info:

MM_sort | fldName | Request.QueryString("sort"
MM_order | ASC | Request.QueryString("order"

And we then change the SQL Query to read:

SELECT *
FROM tblUsers
ORDER BY MM_sort MM_order

----------------------------------

So when page.asp is visited, and there is nothing appended to the end of the URL (ie, it's just page.asp, and not page.asp?sort=fldName&order=ASC) then the rs is created using the DEFAULT VALUES you specified, ie, the rs will look like:

SELECT *
FROM tblUsers
ORDER BY fldName ASC

This will (when page.asp is displayed) sort your information via the field called fldName, and ASCendingly. So boom. Anytime someone visits page.asp, that's the default viewing order (change these to your hearts content)

But now, you saw you want a dropdown list that when selected will alter the rs, right? This is where some simple javascript comes in. Place the following code between the HEAD tags:

&lt;script language="javascript"&gt;
&lt;!--

function autoSort(order){
sorting = document.form1.sortList.value;
ourlocation = document.location.href;
stopat = ourlocation.indexOf("?";
goto = ourlocation.substring(0,stopat);
goto = goto + "?srt=" + sorting + "&ord=" + order;
document.location.href = goto;
}

//--&gt;
&lt;/script&gt;

Then place a dropdown list along with 2 buttons like so in the form on the page:

&lt;form&gt;
&lt;select name="sortList"&gt;
&lt;option value="fldName" selected&gt;Sort by Name&lt;/option&gt;
&lt;option value="fldDate" selected&gt;Sort by Date&lt;/option&gt;
&lt;option value="fldAge" selected&gt;Sort by Age&lt;/option&gt;
&lt;input type = "button" onClick="autoSort('asc') value="ascendingly"&gt;
&lt;input type = "button" onClick="autoSort('desc') value="descendingly"&gt;
&lt;/form&gt;

So here's how the system works.

The user selects Sort by Date, which has a value of fldDate. And then presses DESCendingly. The value DESC is sent to the javascript function sortList(). The variable SORTING is set to the value of the dropdown (fldDate)
The variable OURLOCATION is set to the document's current location. the Variable STOPAT is set to a number where we first find ? in the document location. The variable GOTO now returns from the beginning of the document location string to the STOPAT location, which in essense, what this does is that it returns the page's location itself and truncates any passed values "like order=ASC, etc". So GOTO now contains the page's URL. We now change the GOTO variable to be that page value + sort + order. And then we go there.

Now the page will see the new sort and order in the URL string and parse them (with the Request.QueryString we setup in the variables) and sort the information via the DATE and DESCENDINGLY.
Replied 04 Jul 2002 19:28:27
04 Jul 2002 19:28:27 aegis kleais replied:
On a side note, someone needs to '86 the language filter. It's seriously cheesin me off.

(Also, make sure that your form is using the GET method, and not POST)
Replied 04 Jul 2002 20:05:26
04 Jul 2002 20:05:26 Yael Korin replied:
OK. Now it displays the order I told it in thr default values. still not working eith the list, but maybe it´s because i didn´t add the two bottons, asc and desc, so I guess that the javascript doesen´t know what to do and that´s the problem. is it?
I´ll try later,

Ps: i replaced the name of the form and list in the java, nothing else, ok?



Yae
Replied 04 Jul 2002 20:32:06
04 Jul 2002 20:32:06 aegis kleais replied:
Please post the page code. Also, just for reference, this is not JAVA. JAVA and Javascript are 2 VERY different languages.
Replied 04 Jul 2002 22:59:15
04 Jul 2002 22:59:15 Yael Korin replied:
&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;!--#include file="Connections/ConnGuia.asp" --&gt;
&lt;%
Dim Recordset1__varyear
Recordset1__varyear = "%"
if (Request("year" &lt;&gt; "" then Recordset1__varyear = Request("year"
%&gt;
&lt;%
Dim Recordset1__varmonth
Recordset1__varmonth = "%"
if (Request("month" &lt;&gt; "" then Recordset1__varmonth = Request("month"
%&gt;
&lt;%
Dim Recordset1__varday
Recordset1__varday = "%"
if (Request("day" &lt;&gt; "" then Recordset1__varday = Request("day"
%&gt;
It begins....

&lt;%
Dim Recordset1__varfecha
Recordset1__varfecha = "%"
if (Request("fecha" &lt;&gt; "" then Recordset1__varfecha = Request("fecha"
%&gt;
&lt;%
Dim Recordset1__varbarrio
Recordset1__varbarrio = "%"
if (Request("mnubarrio" &lt;&gt; "" then Recordset1__varbarrio = Request("mnubarrio"
%&gt;
&lt;%
Dim Recordset1__varlocalidad
Recordset1__varlocalidad = "%"
if (Request("mnubarrio" &lt;&gt; "" then Recordset1__varlocalidad = Request("mnubarrio"
%&gt;
&lt;%
Dim Recordset1__vartipo_de_evento
Recordset1__vartipo_de_evento = "%"
if (Request("mnutipoEvento" &lt;&gt; "" then Recordset1__vartipo_de_evento = Request("mnutipoEvento"
%&gt;
&lt;%
Dim Recordset1__varNombreEvento
Recordset1__varNombreEvento = "%"
if (Request("txtsearch" &lt;&gt; "" then Recordset1__varNombreEvento = Request("txtsearch"
%&gt;
&lt;%
Dim Recordset1__MM_sort
Recordset1__MM_sort = "Nombreevento"
if (Request.QueryString("sort" &lt;&gt; "" then Recordset1__MM_sort = Request.QueryString("sort"
%&gt;
&lt;%
Dim Recordset1__MM_order
Recordset1__MM_order = "asc"
if (Request.QueryString("order" &lt;&gt; "" then Recordset1__MM_order = Request.QueryString("order"
%&gt;
&lt;%
set Recordset1 = Server.CreateObject("ADODB.Recordset"
Recordset1.ActiveConnection = MM_ConnGuia_STRING
Recordset1.Source = "SELECT * FROM ConsAgenda WHERE year like '" + Replace(Recordset1__varyear, "'", "''" + "' and month like '" + Replace(Recordset1__varmonth, "'", "''" + "' and day like '" + Replace(Recordset1__varday, "'", "''" + "' and lafecha like '" + Replace(Recordset1__varfecha, "'", "''" + "' and (barrioLugar like '" + Replace(Recordset1__varbarrio, "'", "''" + "' or localidadLugar like '" + Replace(Recordset1__varlocalidad, "'", "''" + "') and tipoEvento like '" + Replace(Recordset1__vartipo_de_evento, "'", "''" + "' and NombreEvento like '" + Replace(Recordset1__varNombreEvento, "'", "''" + "' ORDER BY " + Replace(Recordset1__MM_sort, "'", "''" + " " + Replace(Recordset1__MM_order, "'", "''" + ""
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%&gt;

and then in the head...

&lt;script language="javascript"&gt;
&lt;!--

function autoSort(order){
sorting = document.form1.sortList.value;
ourlocation = document.location.href;
stopat = ourlocation.indexOf("?";
goto = ourlocation.substring(0,stopat);
goto = goto + "?srt=" + sorting + "&ord=" + order;
document.location.href = goto;
}

//--&gt;
&lt;/script&gt;



and the the form...

&lt;form name="form1" method="get" action="agenda.asp"&gt;
&lt;span class="nombre"&gt;&lt;object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" codebase="download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="18" height="18" align="absmiddle"&gt;
&lt;param name=movie value="flash/pulpo%20ch.swf"&gt;
&lt;param name=quality value=high&gt;
&lt;embed src="flash/pulpo%20ch.swf" quality=high pluginspage="www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="18" height="18" align="absmiddle"&gt;
&lt;/embed&gt;
&lt;/object&gt;&lt;/span&gt;
&lt;input type="text" name="txtsearch" class="datos"&gt;
&lt;select name="mnuTipoEvento" class="datos"&gt;
&lt;option value="%" selected&gt;..:: Eleg&iacute;
la categor&iacute;a&lt;/option&gt;
&lt;option value="%"&gt;Todos&lt;/option&gt;
&lt;%
While (NOT RST_de_evento.EOF)
%&gt;
&lt;option value="&lt;%=(RST_de_evento.Fields.Item("TipoEvento".Value)%&gt;"&gt;&lt;%=(RST_de_evento.Fields.Item("TipoEvento".Value)%&gt;&lt;/option&gt;
&lt;%
RST_de_evento.MoveNext()
Wend
If (RST_de_evento.CursorType &gt; 0) Then
RST_de_evento.MoveFirst
Else
RST_de_evento.Requery
End If
%&gt;
&lt;/select&gt;
&lt;br&gt;
&lt;span class="nombre"&gt;&lt;object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" codebase="download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="18" height="18" align="absmiddle"&gt;
&lt;param name=movie value="flash/pulpo%20ch.swf"&gt;
&lt;param name=quality value=high&gt;
&lt;embed src="flash/pulpo%20ch.swf" quality=high pluginspage="www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="18" height="18" align="absmiddle"&gt;
&lt;/embed&gt;
&lt;/object&gt;&lt;/span&gt;
&lt;select name="mnubarrio" class="datos"&gt;
&lt;option value="%" selected&gt;..:: Eleg&iacute;
el barrio&lt;/option&gt;
&lt;option value="Capital Federal"&gt;Todo Capital
Federal&lt;/option&gt;
&lt;option value="BA Norte"&gt;Todo BA Norte&lt;/option&gt;
&lt;option value="BA Sur"&gt;Todo BA Sur&lt;/option&gt;
&lt;option value="BA Oeste"&gt;Todo BA Oeste&lt;/option&gt;
&lt;%
While (NOT RsBarrios.EOF)
%&gt;
&lt;option value="&lt;%=(RsBarrios.Fields.Item("barrioLugar".Value)%&gt;" &gt;&lt;%=(RsBarrios.Fields.Item("barrioLugar".Value)%&gt;&lt;/option&gt;
&lt;%
RsBarrios.MoveNext()
Wend
If (RsBarrios.CursorType &gt; 0) Then
RsBarrios.MoveFirst
Else
RsBarrios.Requery
End If
%&gt;
&lt;/select&gt;
&lt;span class="columna"&gt; ordenar por&lt;/span&gt;
&lt;select name="sortlist" class="datos"&gt;
&lt;option value="fecha" selected&gt;Fecha&lt;/option&gt;
&lt;option value="Tipoevento"&gt;Categorpia&lt;/option&gt;
&lt;option value="Nombreevento"&gt;Nombre&lt;/option&gt;
&lt;/select&gt;
&lt;input type="submit" name="Submit2" value="Listo!" class="TEXT"&gt;
&lt;/form&gt;


Thank you very much for your help.

<img src=../images/dmxzone/forum/icon_smile_shy.gif border=0 align=middle>

Yae
Replied 05 Jul 2002 00:05:58
05 Jul 2002 00:05:58 aegis kleais replied:
Well, your first problem is that you've changed the Javascript/HTML

Where the javascript refers to document.all.sortList.value, you've changed the dropdown box list name from sortList to mnuBarrio. This'll cause problems. And also, you have omited the buttons that are used to activate the function.
Replied 06 Jul 2002 01:53:43
06 Jul 2002 01:53:43 Yael Korin replied:
The name of the menu is sortlist, not mnubarrio, that one is also in the form. The code of the sortlist object is:

&lt;select name="sortlist" class="datos"&gt;
&lt;option value="fecha" selected&gt;Fecha&lt;/option&gt;
&lt;option value="Tipoevento"&gt;Categorpia&lt;/option&gt;
&lt;option value="Nombreevento"&gt;Nombre&lt;/option&gt;
&lt;/select&gt;
&lt;input type = "button" onClick="autoSort('asc') value="ascendingly"&gt;
&lt;input type = "button" onClick="autoSort('desc') value="descendingly"&gt;
&lt;/form&gt;

I put the 2 buttons, but when I preview this in explorer, I get an error in the status bar and the buttons have no label , and do´n´t work, don´t go anywhere.



Yae
Replied 06 Jul 2002 02:40:38
06 Jul 2002 02:40:38 aegis kleais replied:
Double click on the ERROR icon and give the error message. This'll help trouble shoot the problem with the page
Replied 06 Jul 2002 02:50:24
06 Jul 2002 02:50:24 Yael Korin replied:
The error windows says:

line: 176 (wich has no error)
char: 18
Se esperaba (it was expected, in english): ';'
code: 0
Url: ....

and there is a next one, that says the same, but in line 175.



Yae
Replied 06 Jul 2002 03:36:12
06 Jul 2002 03:36:12 aegis kleais replied:
I guess this is my bad again cause I didn't ask for it all, but when you list errors and the errors reference a line, it'd be helpful if we could get the previous 10-20 lines before and after it along with a line count. Thx 8<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle> This seems to be a syntax error.
Replied 06 Jul 2002 08:03:10
06 Jul 2002 08:03:10 Yael Korin replied:
Ok, doen´t work, but i´m giving up<img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle> for now.

But I do have another question!

It´s a short one. In MS Access, i normalized my DB, I hace all this mini tables, and then a querry, so ultradev understands it . But my question is: why to normalize, if at the end, we have a huge querry with all the repeted values? or are we still earning space like this??

And thank you a lot for your help<img src=../images/dmxzone/forum/icon_smile_blush.gif border=0 align=middle>

Yae

Reply to this topic