Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to select all fields non-sequentially? 1

Status
Not open for further replies.
Jul 13, 2001
180
US
Hello.

I have a VBScript statemnet that checks to see if a field value is a particular value which subsequently executes the line of script according to that value.

My problem is this.
On a page that writes all the fields from the database, if I reference the very LAST field (Column) from the database, the rest of the fields do not display on the page. It's as if it skipped the rest of the fields prior to the very last field of the table that I am calling.

For example:

I call this to display

Field1
Field2
Field3
Field4
Field5

But If I call
Field 5 third ,instead of in sequence which would be Field 3

I get this:
Field1
Field2
Field5

Then it ends. Field 3 nor 4 show up.

Is there a way to select all fields non-sequentially or a way around this?

Thanks in advance.

Manny

Posted here after no response in SQL forum.
It is a VBScripy related too I would think. :)
 
Any chance you post some relevant snippets of your code to help us helping you ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hello and thanks PHV.
I tried to shave off as much of the code without cutting off any pertinent info.
Please be aware of and disregard the generated code from Dreamweaver. The focus is on the call of the data from the database.

The code below works fine, however if I take the last item "live" with radio buttons, and place it on top of the page (form)
or anywhere other than the bottom ( being called last from the data table), the rest of the fields below will NOT populate.
The only clue to work with , is that the "live" field is literally listed last on the SQL table it is on.

Pulling my hair out. Agggh!

Thanks in advance for any help.



<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include virtual="/Connections/PressRelease2.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables

If (CStr(Request("MM_update")) = "form1" And CStr(Request("MM_recordId")) <> "") Then

MM_editConnection = MM_PressRelease2_STRING
MM_editTable = "dbo.pressrel"
MM_editColumn = "ID"
MM_recordId = "" + Request.Form("MM_recordId") + ""
MM_editRedirectUrl = "/press/alldone.asp"
MM_fieldsStr = "ID|value|Identifier|value|Title|value|category|value|Short_desc|value|Insert_date|value|Expire_date|value|Created_date|value|created by|value|body|value|livebox|value"
MM_columnsStr = "ID|none,none,NULL|Identifier|',none,''|Title|',none,''|category|',none,''|Short_desc|',none,''|insert_date|',none,NULL|expire_date|',none,NULL|created_date|',none,NULL|created_by|',none,''|body|',none,''|live|none,none,NULL"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim RS_PressRelease__MMColParam
RS_PressRelease__MMColParam = "92"
If (Request.QueryString("ID") <> "") Then
RS_PressRelease__MMColParam = Request.QueryString("ID")
End If
%>

<%
Dim RS_PressRelease
Dim RS_PressRelease_numRows

Set RS_PressRelease = Server.CreateObject("ADODB.Recordset")
RS_PressRelease.ActiveConnection = MM_PressRelease2_STRING
RS_PressRelease.Source = "SELECT * FROM dbo.pressrel WHERE ID = " + Replace(RS_PressRelease__MMColParam, "'", "''") + ""
RS_PressRelease.CursorType = 0
RS_PressRelease.CursorLocation = 2
RS_PressRelease.LockType = 1
RS_PressRelease.Open()

RS_PressRelease_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
for (i=1; i<a.length;i=i+4){
if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
o=MM_findObj(a.replace(/\[\d+\]/ig,""));
o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
v=o.value;t=a[i+2];
if (o.type=='text'||o.type=='password'||o.type=='hidden'){
if (r&&v.length==0){err=true}
if (v.length>0)
if (t==1){ //fromto
ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
} else if (t==2){
rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
} else if (t==3){ // date
ma=a[i+1].split("#");at=v.match(ma[0]);
if(at){
cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
dte=new Date(cy,cm,cd);
if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
}else{err=true}
} else if (t==4){ // time
ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
} else if (t==5){ // check this 2
if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
if(!o1.checked){err=true}
} else if (t==6){ // the same
if(v!=MM_findObj(a[i+1]).value){err=true}
}
} else
if (!o.type&&o.length>0&&o[0].type=='radio'){
at = a.match(/(.*)\[(\d+)\].*/i);
o2=(o.length>1)?o[at[2]]:eek:;
if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
if (t==2){
oo=false;
for(j=0;j<o.length;j++){oo=oo||o[j].checked}
if(!oo){s+='* '+a[i+3]+'\n'}
}
} else if (o.type=='checkbox'){
if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
} else if (o.type=='select-one'||o.type=='select-multiple'){
if(t==1&&o.selectedIndex/1==0){err=true}
}else if (o.type=='textarea'){
if(v.length<a[i+1]){err=true}
}
if (err){s+='* '+a[i+3]+'\n'; err=false}
}
if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
document.MM_returnValue = (s=='');
}
//-->
</script>
</head>

<body bgcolor="#fbeed0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br>

<br>
<table width="94%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="99%" valign="top"><form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">

<table width="95%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="20" rowspan="6" valign="top" background="/images/border1.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td valign="top">&nbsp;</td>
<td width="459">&nbsp;</td>
<td width="98" align="left" valign="top">

<td width="12" rowspan="6" background="/images/border1.gif">&nbsp;&nbsp;&nbsp;</td>
<td width="7" rowspan="6">&nbsp;</td>
</tr>
<tr>
<td valign="top"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">insert_date</font></strong></font></td>
<td colspan="2"><font size="2">
<input name="Insert_date" type="text" class="form" id="Insert_date" value="<%=(RS_PressRelease.Fields.Item("insert_date").Value)%>">
</font></td>
</tr>
<tr>
<td valign="top"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">expire_date</font></strong></font></td>
<td colspan="2"><font size="2">
<input name="Expire_date" type="text" class="form" id="Expire_date" value="<%=(RS_PressRelease.Fields.Item("expire_date").Value)%>">
</font></td>
</tr>
<tr>
<td valign="top"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">created_date</font></strong></font></td>
<td colspan="2"><font size="2">
<input name="Created_date" type="text" class="form" id="Created_date" value="<%=(RS_PressRelease.Fields.Item("created_date").Value)%>">
</font></td>
</tr>
<tr>
<td valign="top"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">created_by</font></strong></font></td>
<td colspan="2"><font size="2">
<input name="created by" type="text" class="form" id="created by" value="<%=(RS_PressRelease.Fields.Item("created_by").Value)%>">
</font></td>
</tr>
<tr>
<td valign="top"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">body<br>
<br>
</font><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">

</font></strong></font></strong></font></td>
<td colspan="2" valign="top"><font size="2">
<textarea name="body" cols="70" rows="33" class="form" id="textarea"><%=(RS_PressRelease.Fields.Item("body").Value)%></textarea>
<% dim onlive
onlive =(RS_PressRelease.Fields.Item("live").Value)
%>
<br>
<br>
<p><span class="style2">live</span> <br>
yes
<input type="radio" name="livebox" value=1 <% If onlive = true Then %>checked<% End If %>>
no
<input type="radio" name="livebox" value=0 <% If onlive = false Then %>checked<% End If %>>
</p>
                                                                                                                             <strong><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">
<input name="Submit" type="submit" class="update" onClick="YY_checkform('form1','category[0]','#q','2','Please categorize this Release.');return document.MM_returnValue" value="Modify"">
&nbsp; </font></strong></font></strong></font></td>
</tr>
</table>


<font size="2">
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= RS_PressRelease.Fields.Item("ID").Value %>">
</font>
</form></td>
<td width="1%" valign="top"><div align="left">
<p><br>
</p>

</div></td>
</tr>
</table>
</body>
</html>

 
And why not assign the database fields (sequentially of course) into variables you can use later (randomly) ?
Or use a Dictionary object.
Or use an array.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks PHV.
I found the problem by comparing it to other pages that I wrote.
The recordset locktype above was= 1, changed it to 3 and all was well.

Don;t ahy that worked , but it did.

Thank you.
 
Odd, worked for one page, but not for another.
Back to square one. Oh well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top