Solved

Ajax and json in my asp classc need help

Posted on 2014-07-25
21
238 Views
Last Modified: 2014-07-29
Trying to get this code to work

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Buffer = false%>
<!-- #include file="db_connection.inc" --> 
{"data": [
<%

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "SELECT artists.ArtistName, Recordings.RecordingTitle FROM dbo.Artists AS artists INNER JOIN dbo.Recordings AS Recordings ON artists.ArtistID = Recordings.ArtistID UNION ALL SELECT artists.ArtistName, NULL RecordingTitle FROM dbo.Artists AS artists ORDER BY ArtistName, RecordingTitle "
Set oRs1=oConn.Execute(strSQL1,lngRecs,1)


' send data to an array'
if not oRs1.eof then
	myArray=oRs1.getrows()
end if

oRs1.Close
Set oRs1 = Nothing
oConn.Close
Set oConn = Nothing




for r = LBound (myArray,2) to UBound(myArray,2)
	artistname 		= myArray(0, r)
	RecordingTitle 	= myArray(1, r)

	'  response.write "['"&artistname&"',"&"'"&RecordingTitle&"']"
	   response.write replace("["&chr(34)&artistname&chr(34)&","&chr(34)&RecordingTitle&chr(34)&","&chr(34)&TrackTitle&chr(34)&","&chr(34)&TrackFileName&chr(34)&"]","\","\\")

        if r < UBound(myArray,2) then
    	response.write ","
    end if


next


%>
]} 

Open in new window






1. I need to add a check box next to the recordingtitle field

2. need to input the check box to
<form method="post" action="music3.asp">

3. Need to add this to the bottom of the page
<button type="submit">Submit</button>  <input type="button" value="BACK!"onClick="history.back();">
</form>

This is json code and ajax

check out the error
http://www.tomsmp3.com/musicatable.asp



Line 30 in my code the response.write I only need artistname and recordingtitle.
cant figure out the right combo to remove the rest of the code.

My response.write is wrong not sure whats up
0
Comment
Question by:Thomas Grassi
  • 11
  • 10
21 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40221048
1) Change the json page to
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Buffer = false%>
<!-- #include file="db_connection.inc" --> 
{"data": [
<%

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "SELECT artists.ArtistName, Recordings.RecordingTitle FROM dbo.Artists AS artists INNER JOIN dbo.Recordings AS Recordings ON artists.ArtistID = Recordings.ArtistID UNION ALL SELECT artists.ArtistName, NULL RecordingTitle FROM dbo.Artists AS artists ORDER BY ArtistName, RecordingTitle "
Set oRs1=oConn.Execute(strSQL1,lngRecs,1)


' send data to an array'
if not oRs1.eof then
	myArray=oRs1.getrows()
end if

oRs1.Close
Set oRs1 = Nothing
oConn.Close
Set oConn = Nothing




for r = LBound (myArray,2) to UBound(myArray,2)
	artistname 		= myArray(0, r)
	RecordingTitle 	= myArray(1, r)

	' <input type="checkbox" value="link">Link
	RecordingTitleCheckBox = "<input name="&"[x]"&"track_title"&&"[x]"&" type="&"[x]"&"checkbox value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle

	'response.write "['"&artistname&"',"&"'"&RecordingTitle&"']"
	 theRow =  replace("["&chr(34)&artistname&chr(34)&","&chr(34)&RecordingTitleCheckBox&chr(34)&"]","\","\\")
	 theRow = replace(theRow,"[x]","\"&chr(34))
	 response.write theRow




        if r < UBound(myArray,2) then
    	response.write ","
    end if


next


%>
]} 

Open in new window

Main page change to
<!DOCTYPE html>
<html>
<head>
<link href="css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/jquery.dataTables.js"></script>

<script>
    $(document).ready(function() {
    $('#example').dataTable( {
        "ajax": 'MusicAJson.asp',
         "deferRender": true
    } );
} )
</script>
  <meta charset="utf-8">
  <title>TomsMP3</title>
</head>
<body>
<form method="post" action="music3.asp">    
    <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Artist Name</th>
                <th>Recording Title</th>
                   
            </tr>
            </thead>
     
            <tfoot>
                <tr>
                    <th>Artist Name</th>
                    <th>Recording Title</th>
                   
                </tr>
            </tfoot>
    </table>
    <button type="submit">Submit</button>  <input type="button" value="BACK!"onClick="history.back();">
</form>   
</body>
</html>

Open in new window

0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40221331
Scott

Thanks for the help

Main table is working now have the form and buttons that great. (musicAtable.asp)

Getting error in musicAjson.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Buffer = false%>
<!-- #include file="db_connection.inc" --> 
{"data": [
<%

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "SELECT artists.ArtistName, Recordings.RecordingTitle FROM dbo.Artists AS artists INNER JOIN dbo.Recordings AS Recordings ON artists.ArtistID = Recordings.ArtistID UNION ALL SELECT artists.ArtistName, NULL RecordingTitle FROM dbo.Artists AS artists ORDER BY ArtistName, RecordingTitle "
Set oRs1=oConn.Execute(strSQL1,lngRecs,1)

' send data to an array'
if not oRs1.eof then
	myArray=oRs1.getrows()
end if

oRs1.Close
Set oRs1 = Nothing
oConn.Close
Set oConn = Nothing

for r = LBound (myArray,2) to UBound(myArray,2)
	    artistname 		= myArray(0, r)
	    RecordingTitle 	= myArray(1, r)
	
        ' <input type="checkbox" value="link">Link
	    RecordingTitleCheckBox = "<input name="&"[x]"&"track_title"&&"[x]"&" type="&"[x]"&"checkbox value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle

	    'response.write "['"&artistname&"',"&"'"&RecordingTitle&"']"
	    theRow =  replace("["&chr(34)&artistname&chr(34)&","&chr(34)&RecordingTitleCheckBox&chr(34)&"]","\","\\")
	    theRow = replace(theRow,"[x]","\"&chr(34))
	    response.write theRow
	    
        if r < UBound(myArray,2) then
    	response.write ","
	
    end if
next
%>
]}

Open in new window


I am looking at lines 22 thru 37 but can not see anything in the code.

on line 27 at the end is "&recordingTitle missing anything?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40222201
That is line 31 above

RecordingTitleCheckBox = "<input name="&"[x]"&"track_title"&&"[x]"&" type="&"[x]"&"checkbox value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle

Open in new window


should be below by taking out the double &&

RecordingTitleCheckBox = "<input name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"checkbox value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle

Open in new window


fyi, I am currently using my cell phone hotspot for the next couple of weeks.  If you need help troubleshooting this, please set your musicjson.asp page to only list the first 50 records so I don't have to worry about my data package.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40222434
Scott

Thanks for the response.

the above change now the page display.

I set the rowcount to 50 for now.

1. the check box displays but it is very large
If you look at this page http://www.tomsmp3.com/AlbumSearch.asp that is the size I would like

2. I can not click in the check box  need to click on the check box to make the selection for the submit button to work

my current code

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Buffer = false%>
<!-- #include file="db_connection.inc" --> 
{"data": [
<%

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "set rowcount 50 SELECT artists.ArtistName, Recordings.RecordingTitle FROM dbo.Artists AS artists INNER JOIN dbo.Recordings AS Recordings ON artists.ArtistID = Recordings.ArtistID UNION ALL SELECT artists.ArtistName, NULL RecordingTitle FROM dbo.Artists AS artists ORDER BY ArtistName, RecordingTitle "
Set oRs1=oConn.Execute(strSQL1,lngRecs,1)

' send data to an array'
if not oRs1.eof then
	myArray=oRs1.getrows()
end if

oRs1.Close
Set oRs1 = Nothing
oConn.Close
Set oConn = Nothing

for r = LBound (myArray,2) to UBound(myArray,2)
	    artistname 		= myArray(0, r)
	    RecordingTitle 	= myArray(1, r)
	
        ' <input type="checkbox" value="link">Link
	    RecordingTitleCheckBox = "<input name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"checkbox value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle

	    theRow =  replace("["&chr(34)&artistname&chr(34)&","&chr(34)&RecordingTitleCheckBox&chr(34)&"]","\","\\")
	    theRow = replace(theRow,"[x]","\"&chr(34))
	    response.write theRow
	    
        if r < UBound(myArray,2) then
    	response.write ","
	
    end if
next
%>
]}

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40222697
RecordingTitleCheckBox = "<input name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"checkbox value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle

Open in new window



to

RecordingTitleCheckBox = "<input type="&"[x]"&checkbox&"[x]"&"  name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle

Open in new window

0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40222709
Scott

Same results

check box large
check box cannot click into

Check it
http://www.tomsmp3.com/musicatable.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Buffer = false%>
<!-- #include file="db_connection.inc" --> 
{"data": [
<%

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "set rowcount 50 SELECT artists.ArtistName, Recordings.RecordingTitle FROM dbo.Artists AS artists INNER JOIN dbo.Recordings AS Recordings ON artists.ArtistID = Recordings.ArtistID UNION ALL SELECT artists.ArtistName, NULL RecordingTitle FROM dbo.Artists AS artists ORDER BY ArtistName, RecordingTitle "
Set oRs1=oConn.Execute(strSQL1,lngRecs,1)

' send data to an array'
if not oRs1.eof then
	myArray=oRs1.getrows()
end if

oRs1.Close
Set oRs1 = Nothing
oConn.Close
Set oConn = Nothing

for r = LBound (myArray,2) to UBound(myArray,2)
	    artistname 		= myArray(0, r)
	    RecordingTitle 	= myArray(1, r)
	
        ' <input type="checkbox" value="link">Link
'        RecordingTitleCheckBox = "<input name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"checkbox value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle
	    RecordingTitleCheckBox = "<input type="&"[x]"&checkbox&"[x]"&"  name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle
	    theRow =  replace("["&chr(34)&artistname&chr(34)&","&chr(34)&RecordingTitleCheckBox&chr(34)&"]","\","\\")
	    theRow = replace(theRow,"[x]","\"&chr(34))
	    response.write theRow
	    
        if r < UBound(myArray,2) then
    	response.write ","
	
    end if
next
%>
]}

Open in new window

0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 40222735
RecordingTitleCheckBox = "<input type="&"[x]"&"checkbox"&"[x]"&"  name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle

Open in new window

0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40222743
Scott

now looks good and the check boxes by clicking on them work too.

when I check a few then hit the submit button which load into form from musicAtable.asp I get a blank page from music3.asp

looks like no data is being passed to the form

check it out    select a few and then click on the submit button

http://www.tomsmp3.com/musicatable.asp
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40222771
If it is going to music3.asp, then the name needs to change to selectItem and the value needs to look like M:\Music\MP3MusicAlbums\!!!\Me and Guiliani Down by the Sc\01-Me and Guiliani Down by the Sc-Me and Guiliani Down by the Schoolyard.mp3
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40222875
Scott

This is the code that I am trying to replace with the ajax and json

This code is on the current production page
albumsearch.asp      that calls selectalbums.asp which posts data to music3.asp

Now
albumsearch.asp  being replaced by musicAtable.asp
selectalbums.asp being replaced by musicajson.asp
music3.asp stays the same.

here is the code:

albumsearch.asp
<%@language=vbscript%>
<%Response.Buffer = True%>
<html>
<head>
<script type="text/javascript" src="js/GA-MP3.js"></script>
</head>
<form name="input" action="SelectAlbums.asp" method="post">
<%
Response.Write "Make Your Selections To View all Songs from the Albums then click on Submit button<br />"
Response.Write "<br />"
	Dim strStartPath, i, strPreviousFolder
	i = 0
	strStartPath = "M:\MUSIC\MP3MUSICALBUMS" 'ENTER YOUR START FOLDER HERE
	If Right(strStartPath, 1) <> "\" Then strStartPath = strStartPath & "\"
	strPreviousFolder = ""
	ListFolder strStartPath
	Response.Write "<BR><BR>Total Albums : " & i  
Sub ListFolder(sFolderPath)
	Set FS = CreateObject("Scripting.FileSystemObject")
	Set FSfolder = FS.GetFolder(sFolderPath)
	strCurrentFolder = Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare)
	If InStr(strCurrentFolder, "\") > 0 Then strCurrentFolder = Left(strCurrentFolder, InStr(strCurrentFolder, "\") - 1)
	If strCurrentFolder <> strPreviousFolder Then
		Response.Write "<BR>"
		strPreviousFolder = strCurrentFolder
	End If
	If strCurrentFolder <> "" Then
		i = i + 1
    	Response.Write "<BR><input type='checkbox' id='chkAlbum" & i & "' name='chkAlbum' value='" & makeAlbumName(Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare)) & "'>" & makeAlbumName(Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare))
    	End If
	For Each subfolder In FSfolder.SubFolders
		ListFolder subfolder.Path
	Next
End Sub

function makeAlbumName(fullstring)
	findSlash = instr(fullstring,"\") 
	makeAlbumName = right(fullstring,len(fullstring)-findSlash)
end function

%>

<button type="submit">Submit</button>  <input type="button" value="BACK!"onClick="history.back();">
</form>
</html>

Open in new window


selectalbums.asp
<!-- #include file="db_connection.inc" -->
<%
dim searchWord, searchIN
dim strFont1
dim strFont2
searchIN = ""

goodData=0

searchWord = Request.form("chkAlbum") 'change form to method post 

if searchWord <> "" then
arrSearchWord = split(searchWord,",") ' convert to array'
for each phrase in arrSearchWord
    searchIN=searchIN & "'" & Trim( phrase ) & "'," 
next
searchIN=left(searchIN,len(searchIN)-1) ' remove the last comma'

strFont1 = "<font style=""font-size: 20px; color: #ff0000; font-family:verdana"">"
strFont2 = "<font style=""font-size: 16px; color: #000000; font-family:verdana"">"

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "SELECT dbo.Artists.artistname, dbo.Recordings.RecordingTitle, dbo.Tracks.TrackTitle, dbo.Tracks.TrackFileName FROM  dbo.Artists INNER JOIN dbo.Recordings ON dbo.Artists.artistid = dbo.Recordings.ArtistID INNER JOIN dbo.Tracks ON dbo.Recordings.RecordingID = dbo.Tracks.RecordingID WHERE     (dbo.Artists.artistname IN ("&searchIN&") or (dbo.Recordings.recordingtitle IN ("&searchIN&")))"

Set oRs1=oConn.Execute(strSQL1,lngRecs,1)
if not oRs1.eof then
	goodData=1
	arrResults=oRs1.getrows()
end if

end if

%>

<form method="post" action="music3.asp">

<%
Response.Write strFont1 & "Select Songs you Wish to Add to Your Playlist then click on Submit button<br />"
Response.Write "<br />"

if goodData =1 then
   For r = LBound(arrResults, 2) To UBound(arrResults, 2)
   		artistname		= arrResults(0,r)
   		RecordingTitle	= arrResults(1,r)
   		TrackTitle		= arrResults(2,r)
   		TrackFileName	= arrResults(3,r)
       	response.write strFont2 & "<div class=""results""><input type=""checkbox"" name=""selectItem"" value="""&TrackFileName&"""> "&artistname&" "&RecordingTitle&" "&TrackTitle&" "&TrackFileName&"</div>"
    next
else


Response.Write "no artists selected"   
end if


%>
<button type="submit">Submit</button>  <input type="button" value="BACK!"onClick="history.back();">
</form>

Open in new window



music3.asp    this one is used by other pages and works for all of them

<%
if request.form<>"" then
dim fs,fname, pathToPlayList
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("m:\playlist\myplaylist_"&Session.SessionID&".m3u",true)

pathToPlayList="/playlist/myplaylist_"&Session.SessionID&".m3u"

strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
fname.WriteLine "#EXTM3U" '** M3U'
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   fname.WriteLine "#EXTINF:000, "& makeSongName(song)
   fname.WriteLine "http://www.tomsmp3.com"&replace(replace(replace(trim(song),"M:\Music","/mp3"),"\","/")," ","%20")
   next
response.write "</ul>" 
fname.Close
else
response.write "You did not post any data yet<br>"
end if
set fname=nothing
set fs=nothing

function makeSongName(song)
	 p = InStrRev(song,"\",-1)
     makeSongName = mid(song,p+1,len(song)-p)
end function
%>
<input type="button" value="BACK!"onClick="history.back();">
<button value="Playlist" onclick="window.location = '<%=pathToPlayList%>'"> Playlist </button>

Open in new window



now for what we are trying to do.

musicAtable.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html>
<html>
<head>
<link href="css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/jquery.dataTables.js"></script>

<script>
    $(document).ready(function() {
    $('#example').dataTable( {
        "ajax": 'MusicAJson.asp',
         "deferRender": true
    } );
} )
</script>
  <meta charset="utf-8">
  <title>TomsMP3</title>
</head>
<body>
<form method="post" action="music3.asp">
<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Artist Name</th>
                <th>Recording Title</th>
               
            </tr>
        </thead>
 
        <tfoot>
            <tr>
                <th>Artist Name</th>
                <th>Recording Title</th>
               
            </tr>
        </tfoot>
    </table>
    <button type="submit">Submit</button>  <input type="button" value="BACK!"onClick="history.back();">
</form>   
</body>
</html>

Open in new window


musicAjson.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Buffer = false%>
<!-- #include file="db_connection.inc" --> 
{"data": [
<%

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "set rowcount 50 SELECT artists.ArtistName, Recordings.RecordingTitle FROM dbo.Artists AS artists INNER JOIN dbo.Recordings AS Recordings ON artists.ArtistID = Recordings.ArtistID UNION ALL SELECT artists.ArtistName, NULL RecordingTitle FROM dbo.Artists AS artists ORDER BY ArtistName, RecordingTitle "
Set oRs1=oConn.Execute(strSQL1,lngRecs,1)

' send data to an array'
if not oRs1.eof then
	myArray=oRs1.getrows()
end if

oRs1.Close
Set oRs1 = Nothing
oConn.Close
Set oConn = Nothing

for r = LBound (myArray,2) to UBound(myArray,2)
	    artistname 		= myArray(0, r)
	    RecordingTitle 	= myArray(1, r)
	
        ' <input type="checkbox" value="link">Link
	    RecordingTitleCheckBox = "<input type="&"[x]"&"checkbox"&"[x]"&"  name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle
	    theRow =  replace("["&chr(34)&artistname&chr(34)&","&chr(34)&RecordingTitleCheckBox&chr(34)&"]","\","\\")
	    theRow = replace(theRow,"[x]","\"&chr(34))
	    response.write theRow
	    
        if r < UBound(myArray,2) then
    	response.write ","
	
    end if
next
%>
]}

Open in new window


we need musicAjson to pass the data the same as selectalbums.asp does

www.tomsmp3.com    select all albums to see how the current one works

http://www.tomsmp3.com/musicatable.asp  for what we are working on now.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40222995
Those don't help because they were using the file system.  In the previous question, we had this working where TrackFileName was being output.  You will need to go back to it and find what the sql statment was.  http://www.experts-exchange.com/Programming/Languages/Scripting/ASP/Q_28469969.html

You will also need to update the statement that starts with: for r = LBound (myArray,2) to UBound(myArray,2) to include the field for the file name.

Finally in the line that builds the checkbox, you will need to change the field name to match as I mentioned.  And change the value to the output of the file name.  Looking below, the name is currently set to track_title  and the value is RecordingTitle.

Make those changes on your own and see what you can come up with.

RecordingTitleCheckBox = "<input type="&"[x]"&"checkbox"&"[x]"&"  name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle

Open in new window

0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40223118
Scott

Thanks

You mean model it after this one?

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Buffer = false%>
<!-- #include file="db_connection.inc" --> 
{"data": [
<%

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "SELECT dbo.Artists.artistname, dbo.Recordings.RecordingTitle, dbo.Tracks.TrackTitle, dbo.Tracks.TrackFileName FROM  dbo.Artists INNER JOIN dbo.Recordings ON dbo.Artists.artistid = dbo.Recordings.ArtistID INNER JOIN dbo.Tracks ON dbo.Recordings.RecordingID = dbo.Tracks.RecordingID "
Set oRs1=oConn.Execute(strSQL1,lngRecs,1)


' send data to an array'
if not oRs1.eof then
	myArray=oRs1.getrows()
end if

oRs1.Close
Set oRs1 = Nothing
oConn.Close
Set oConn = Nothing



for r = LBound (myArray,2) to UBound(myArray,2)
	artistname 		= myArray(0, r)
	RecordingTitle 	= myArray(1, r)
	TrackTitle 		= myArray(2, r)
	TrackFileName 	= myArray(3, r)

	TrackFileUrl = replace(TrackFileName,"M:\Music\","\mp3\")

	'M:\Music\MP3MusicAlbums\!!!\Louden Up Now\01-Louden Up Now-When The Going Gets Tough The Tough Gets Krazee.mp3

	' convert to'
	'\mp3\MP3MusicAlbums\!!!\Louden Up Now\01-Louden Up Now-When The Going Gets Tough The Tough Gets Krazee.mp3

	TrackFileLink = "<a href="&"[x]"&TrackFileUrl&"[x]"&">"&TrackTitle&"</a>"

    theURL = replace("["&chr(34)&artistname&chr(34)&","&chr(34)&RecordingTitle&chr(34)&","&chr(34)&TrackTitle&chr(34)&","&chr(34)&TrackFileLink&chr(34)&"]","\","\\")
    theURL = replace(theURL,"[x]","\"&chr(34))
    response.write theURL

        if r < UBound(myArray,2) then
    	response.write ","
    end if


next


%>
]}

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40223139
The link below was already your answer except for it was displaying text instead of a checkbox.  I'm not sure why you changed the sql statement for this question.    Just switch out the field name and value to the checkbox you already have.

http:Q_28469969.html#a40206249
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40223376
Scott

Switched to SQL because it is faster than searching the drive,

I think we have this statement in the wrong place.

<form method="post" action="music3.asp">

I think it need to go into musicAjson.asp

musicajson.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Buffer = false%>
<!-- #include file="db_connection.inc" --> 
{"data": [
<%

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "set rowcount 50 SELECT artists.ArtistName, Recordings.RecordingTitle FROM dbo.Artists AS artists INNER JOIN dbo.Recordings AS Recordings ON artists.ArtistID = Recordings.ArtistID UNION ALL SELECT artists.ArtistName, NULL RecordingTitle FROM dbo.Artists AS artists ORDER BY ArtistName, RecordingTitle "
Set oRs1=oConn.Execute(strSQL1,lngRecs,1)

' send data to an array'
if not oRs1.eof then
	myArray=oRs1.getrows()
end if

oRs1.Close
Set oRs1 = Nothing
oConn.Close
Set oConn = Nothing

for r = LBound (myArray,2) to UBound(myArray,2)
	    artistname 		= myArray(0, r)
	    RecordingTitle 	= myArray(1, r)
	
        ' <input type="checkbox" value="link">Link
	    RecordingTitleCheckBox = "<input type="&"[x]"&"checkbox"&"[x]"&"  name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle
	    theRow =  replace("["&chr(34)&artistname&chr(34)&","&chr(34)&RecordingTitleCheckBox&chr(34)&"]","\","\\")
	    theRow = replace(theRow,"[x]","\"&chr(34))
	    response.write theRow
	    
        if r < UBound(myArray,2) then
    	response.write ","
	
    end if
next
%>
]}

Open in new window


Where and how

musicAjson.asp produces the list

musicAtable.asp is the front end so should not be there is my thinking what do you think?


musicatable.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html>
<html>
<head>
<link href="css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/jquery.dataTables.js"></script>

<script>
    $(document).ready(function() {
    $('#example').dataTable( {
        "ajax": 'MusicAJson.asp',
         "deferRender": true
    } );
} )
</script>
  <meta charset="utf-8">
  <title>TomsMP3</title>
</head>
<body>
<form method="post" action="music3.asp">
<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Artist Name</th>
                <th>Recording Title</th>
               
            </tr>
        </thead>
 
        <tfoot>
            <tr>
                <th>Artist Name</th>
                <th>Recording Title</th>
               
            </tr>
        </tfoot>
    </table>
    <button type="submit">Submit</button>  <input type="button" value="BACK!"onClick="history.back();">
</form>   
</body>
</html>

Open in new window



line 21 ???

I think if we get line 21 in the correct place it might work without any further changes
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40223409
the form is in the correct place.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40225669
Scott

After a day thinking about this I must be giving you the wrong info.

The question you pointed me too as being the answer is not correct.
That page is different than this one. I has one page where you search for all the songs and the other page is for making the selection and displaying the results.

Now this page Search for all Albums

First step  List all Albums with check box
Second step pass selected item to music3.asp which lists the checked items with a check box then you can check them and create a playlist.  music3.asp is used by other pages.

With musicAtable.asp and musicAJson.asp I think they are just like the above first program just listing all the albums.

May we need another asp page to which I already have selectalbums.asp

I think I need to change lines 27 28 29 & 30 ??  to something like this
          Response.Write "<BR><input type='checkbox' id='chkAlbum" & i & "' name='chkAlbum' value='" & makeAlbumName(Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare)) & "'>" & makeAlbumName(Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare))


Then in musicAtable.asp change line 21 from <form method="post" action="music3.asp">
to  <form name="input" action="SelectAlbums.asp" method="post">

Am I on the right track?

Thoughts
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40225685
Go back to the end.  What is the output supposed to look like in raw html.  Then work back into your asp code needed to generate y our sample html code.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40225791
Scott

Made some changes .

MusicAtable.asp now calls selectalbums.asp not music3.asp
selectalbums.asp calls music3.asp.

Almost have it working.

Just need some help on this

I need musinajson.asp to  to have an ID='chkalbum'  in the response write.  This line works which is currently in production

          Response.Write "<BR><input type='checkbox' id='chkAlbum" & i & "' name='chkAlbum' value='" & makeAlbumName(Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare)) & "'>" & makeAlbumName(Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare))

But that is from the code that uses the file system to search thru

How do I get musicajson to output the same


code for musicajson.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Response.Buffer = false%>
<!-- #include file="db_connection.inc" --> 
{"data": [
<%

Set oConn=Server.CreateObject("ADODB.Connection") 
oConn.Open strConnect
strSQL1 = "set rowcount 50 SELECT artists.ArtistName, Recordings.RecordingTitle FROM dbo.Artists AS artists INNER JOIN dbo.Recordings AS Recordings ON artists.ArtistID = Recordings.ArtistID UNION ALL SELECT artists.ArtistName, NULL RecordingTitle FROM dbo.Artists AS artists ORDER BY ArtistName, RecordingTitle "
Set oRs1=oConn.Execute(strSQL1,lngRecs,1)

' send data to an array'
if not oRs1.eof then
	myArray=oRs1.getrows()
end if

oRs1.Close
Set oRs1 = Nothing
oConn.Close
Set oConn = Nothing

for r = LBound (myArray,2) to UBound(myArray,2)
	    artistname 		= myArray(0, r)
	    RecordingTitle 	= myArray(1, r)
	
        ' <input type="checkbox" value="link">Link
	    RecordingTitleCheckBox = "<input type="&"[x]"&"checkbox"&"[x]"&"  name="&"[x]"&"track_title"&"[x]"&" type="&"[x]"&"value="&"[x]"&RecordingTitle&"[x]"&">"&RecordingTitle
	    theRow =  replace("["&chr(34)&artistname&chr(34)&","&chr(34)&RecordingTitleCheckBox&chr(34)&"]","\","\\")
	    theRow = replace(theRow,"[x]","\"&chr(34))
	    response.write theRow
	    
        if r < UBound(myArray,2) then
    	response.write ","
	
    end if
next
%>
]}

Open in new window



The file system one was only writing out Artist Name and RecordingTitle.

That code was this

<%@language=vbscript%>
<%Response.Buffer = True%>
<html>
<head>
<script type="text/javascript" src="js/GA-MP3.js"></script>
</head>
<form name="input" action="SelectAlbums.asp" method="post">
<%
Response.Write "Make Your Selections To View all Songs from the Albums then click on Submit button<br />"
Response.Write "<br />"
	Dim strStartPath, i, strPreviousFolder
	i = 0
	strStartPath = "M:\MUSIC\MP3MUSICALBUMS" 'ENTER YOUR START FOLDER HERE
	If Right(strStartPath, 1) <> "\" Then strStartPath = strStartPath & "\"
	strPreviousFolder = ""
	ListFolder strStartPath
	Response.Write "<BR><BR>Total Albums : " & i  
Sub ListFolder(sFolderPath)
	Set FS = CreateObject("Scripting.FileSystemObject")
	Set FSfolder = FS.GetFolder(sFolderPath)
	strCurrentFolder = Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare)
	If InStr(strCurrentFolder, "\") > 0 Then strCurrentFolder = Left(strCurrentFolder, InStr(strCurrentFolder, "\") - 1)
	If strCurrentFolder <> strPreviousFolder Then
		Response.Write "<BR>"
		strPreviousFolder = strCurrentFolder
	End If
	If strCurrentFolder <> "" Then
		i = i + 1
    	Response.Write "<BR><input type='checkbox' id='chkAlbum" & i & "' name='chkAlbum' value='" & makeAlbumName(Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare)) & "'>" & makeAlbumName(Replace(sFolderPath, strStartPath, "", 1, -1, vbTextCompare))
    	End If
	For Each subfolder In FSfolder.SubFolders
		ListFolder subfolder.Path
	Next
End Sub

function makeAlbumName(fullstring)
	findSlash = instr(fullstring,"\") 
	makeAlbumName = right(fullstring,len(fullstring)-findSlash)
end function

%>

<button type="submit">Submit</button>  <input type="button" value="BACK!"onClick="history.back();">
</form>
</html>

Open in new window



If we get the routine on lines 22 thru 34 in musicajson.asp to work I think we have this working.

Just need your expert help on this code change

Thanks
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40225946
This is the format the checkbox needs to be to get to music3.asp

<input type="checkbox" name="selectItem" value="M:\Music\MP3MusicAlbums\100 Proof Aged In Soul\Billboard Top 100 - 1970\01-Billboard Top 100 - 1970-84 Somebodys Been Sleeping.mp3">

Open in new window


>I need musinajson.asp to  to have an ID='chkalbum'

You can't do that because that would create multiple id's that are identical.  ID's need to be unique, classes can be duplicates.
0
 
LVL 23

Author Closing Comment

by:Thomas Grassi
ID: 40227888
Scott

Closing this out for now.

Going to work on the other part later this week I will post questions then.

I need to better explain what I am trying to do here with this page.

Have a friend coming in from LA tonight so I thought I would close this out

Thanks for all your help
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40228397
Ok, I will have more time in another week too.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now