musicradiolive Posted November 14, 2007 Share Posted November 14, 2007 Hi.I need some help working out how to do something.As part of my radio stations website re-development, the new website management system will allow the Dj's to manage pages within the site, which i have aced .The only problem i've ran into is our chart editor. The system will allow Dj's to update their charts on the site.In the database is a table that has the following fields:ID - AUTO NUMBERNAME - NAME OF THE CHARTTRACKS - THE NUMBER OF TRACKS IN THE CHART-----------------------The next table contains the chart data.ID - AUTO NUMBERCHART - NUMBER (CORRESPONDING TO ID IN THE PREVIOUS TABLE)POSITION - THIS WEEKS POSITION (1, 2 ETC)ARTIST - THE TRACK ARTISTTRACK - THE TRACK NAMESTATUS - STATUS IN THE CHART (I.E. No Move, Down, Up, New Entry)MOVE - NUMBER OF POSITIONS MOVED (IF APPLICABLE)CDATE - THE DATE OF THE CHART------------------------Using the values in the table fields, they get sent to the chart creator page.In the querystring is the following:CHART= ("id number of the chart")TRACKS = ("the number of tracks in the chart")Knowing which chart to update isn't a problem the BIG problem is the number of tracks.I want it to build a form depending of this numberFor example <form method="post" action="sendhere.asp?chart=<% =Request.Querystring("chart") %>">Chart Date: <input type="text" name="text" value="MM/DD/YYYY"><table width="700" border="1" cellpadding="0" cellspacing="0"><tr><td>POSITION</td><td>ARTIST</td><td>TRACK NAME</td><td>STATUS</td><td>MOVE</td></tr><% 'TAKE THE NUMBER IN THE QUERYSTRING HERE TO BUILD THE FORM %><% <% DIM fields = RequestQuerystring("tracks") %><% 'COUNT THE NUMBER SPECIFIED WITHIN FIELDS / TRAKS QUERYSTRING AND BUILD THE TABLE BASED ON IT, FOR EACH NUMBER CREATE THIS: %><tr><td><input type="text" readonly="yes" name="position"></td><td><input type="text" name="artist"></td><td><input type="text" name="name"></td><td><select name="status"><OPTION>NO MOVE</OPTION><OPTION>DOWN</OPTION><OPTION>UP</OPTION><OPTION>NEW ENTRY</OPTION></select></td><td><input type="text" name="move"></td></tr><% 'loop it here'now close it here %><tr><td colspan="5"><input type="submit" value="SAVE CHART"></td></tr></table> My next problem is the taking each track and inserting it as a seperate record, any ideas how i do that? All help is appreciated.ThanksJon Link to comment Share on other sites More sharing options...
justsomeguy Posted November 14, 2007 Share Posted November 14, 2007 The easiest way is to just pass the number of tracks in a hidden input and numbering the fields. You can use a for loop to write the fields. <input type="hidden" name="tracks" value="<%=fields%>"><%for i = 1 to fields%><tr><td><input type="text" readonly="yes" name="position_<%=i%>"></td><td><input type="text" name="artist_<%=i%>"></td><td><input type="text" name="name_<%=i%>"></td><td><select name="status_<%=i%>"><OPTION>NO MOVE</OPTION><OPTION>DOWN</OPTION><OPTION>UP</OPTION><OPTION>NEW ENTRY</OPTION></select></td><td><input type="text" name="move_<%=i%>"></td></tr><%next%> On the processing page you can get the number of tracks and do a similar loop to read the information for that track. Link to comment Share on other sites More sharing options...
musicradiolive Posted November 15, 2007 Author Share Posted November 15, 2007 Thanks for that, it worked a treat to create the table and form.I'm still having problems getting the processing page to work.FORM NOW LOOKS LIKE THIS: <form method="post" action="sendhere.asp?chart=<% =request.querystring("chart") %>&tracks=<% =Request.QueryString("tracks") %>"><font class="style1">Chart Date:</font> <input class="style1" type="text" name="ChartDate" value="DD.MM.YYYY" /><table class="style1" width="530" border="1" cellpadding="0" cellspacing="0"><tr><td width="60"> Position</td><td> Artist</td><td> Track Name</td><td> Status</td><td width="60"> Move</td></tr><%for i = 1 to request.QueryString("tracks")%><tr><td><input class="style1" size="3" type="text" readonly="yes" name="position<% =i %>" value="<% =i %>"></td><td><input class="style1" type="text" name="tartist<% =i %>"></td><td><input class="style1" type="text" name="tname<% =i %>"></td><td><select class="style1" name="tstatus<% =i %>"><OPTION>NO MOVE</OPTION><OPTION>DOWN</OPTION><OPTION>UP</OPTION><OPTION>NEW ENTRY</OPTION></select></td><td><input class="style1" size="3" type="text" name="tmove<%=i%>"></td></tr><%next%><tr><td colspan="5"><div align="center"><input class="style1" type="submit" value="SAVE CHART" /></div></td></tr></table></form> The processing page looks like this: <% strSql = "SELECT * FROM tblChartTables"rs.CursorType = 2rs.LockType = 3rs.open strSQL, adoConrs.AddNew if err.number <> 0 then response.write(sql) if adocon.errors.count > 0 then for each e in adocon.errors response.write e.description & "<br>" next end if response.end end if rs.Fields("CDate") = Request.Form("ChartDate")for i = 1 to request.QueryString("tracks")rs.fields("chart") = Request.QueryString("chart")rs.Fields("position") = Request.Form("position" & (i) & "")rs.Fields("artist") = Request.Form("tartist" & (i) & "")rs.Fields("track") = Request.Form("tname" & (i) & "")rs.Fields("status") = Request.Form("tstatus" & (i) & "")rs.Fields("move") = Request.Form("tmove" & (i) & "")nextrs.Update%> Link to comment Share on other sites More sharing options...
justsomeguy Posted November 15, 2007 Share Posted November 15, 2007 I don't typically use recordsets like that, I just send an update or insert query instead of using the rs.update method, but it seems fine. The only thing I can think of is that you are trying to insert but you're using an update statement. I'm not sure if the recordset object has an insert method, but you need to be inserting I believe. I'm just not sure how to do it using that syntax. Link to comment Share on other sites More sharing options...
musicradiolive Posted November 17, 2007 Author Share Posted November 17, 2007 Any ideas on re-writing the processing page then?How would you have done it? Link to comment Share on other sites More sharing options...
Reg Edit Posted November 17, 2007 Share Posted November 17, 2007 Any ideas on re-writing the processing page then?How would you have done it?From memory, AddNew/Update is the correct sequence for an insert. But if you want to insert a record for each track, your logic needs to be:for i = 1 to request.QueryString("tracks") rs.AddNew rs.Fields("CDate") = Request.Form("ChartDate") rs.fields("chart") = Request.QueryString("chart") rs.Fields("position") = Request.Form("position" & (i) & "") rs.Fields("artist") = Request.Form("tartist" & (i) & "") rs.Fields("track") = Request.Form("tname" & (i) & "") rs.Fields("status") = Request.Form("tstatus" & (i) & "") rs.Fields("move") = Request.Form("tmove" & (i) & "") rs.Updatenext Link to comment Share on other sites More sharing options...
justsomeguy Posted November 19, 2007 Share Posted November 19, 2007 I just do it like this, in java script: var dbcon = Server.CreateObject("ADODB.Recordset");dbcon.ActiveConnection = db_con_string;dbcon.Open("INSERT INTO..."); Using a normal SQL query. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.