ok i have this page that lists jobs from a database, and when u click on a job it brings up a popup with the detials of the job. only thing is i cant get it to match up the right details with the right jobs.. i tried the MoveNext command but i already use that at to list the jobs...
if i understand correctly id need to use an ID thing and link the 2 up using there IDs, but im not sure how too.... could someone help me out please.
here's the code:
Code:
<html>
<body>
<%
Dim adoCon
Dim rsGuestbook
Dim strSQL
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("jobs.mdb")
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT jobs.Id_no, jobs.EmailAddress, jobs.JobTitle, jobs.Salary1, jobs.Salary2, jobs.SalaryRateOTE, jobs.SalaryRateIncBen, jobs.SalaryRateProRata, jobs.SalaryRateNegShow, jobs.SalaryRateNegHide, jobs.Town, jobsector.Name AS jobsector, type.Name AS type, per.Name AS per, region.Name AS region FROM jobs, jobsector, type, per, region WHERE jobsector.Id = jobs.jobsectorId AND type.Id = jobs.typeId AND per.Id = jobs.perId AND region.Id = jobs.regionId;"
rsGuestbook.Open strSQL, adoCon
Do While not rsGuestbook.EOF
%>
<SCRIPT TYPE='text/javascript'>
<!--
function popup(width,height){
if(window.innerWidth){
LeftPosition =(window.innerWidth-width)/2;
TopPosition =((window.innerHeight-height)/4)-50;
}
else{
LeftPosition =(parseInt(window.screen.width)- width)/2;
TopPosition=((parseInt(window.screen.height)-height)/2)-50;
}
attr = 'resizable=no,scrollbars=yes,width=' + width + ',height=' +
height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
TopPosition + '';
popWin=open('', 'new_window', attr);
popWin.document.write('<head><title>Test Popup</title></head>');
popWin.document.write('<body><div align=center>');
popWin.document.write('<b>This is a test popup window</b><br><br>');
popWin.document.write('<%=rsGuestbook("Town")%><br>');
popWin.document.write('Content goes here<br>');
popWin.document.write('Content goes here<br>');
popWin.document.write('</div></body></html>');
}
//-->
</SCRIPT>
Job Title: <a href="javascript:popup(400,200);"><%=rsGuestbook("JobTitle")%><br></a>
<%
rsGuestbook.MoveNext
Loop
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
%>
</body>
</html>
You will need to redesign your database if you have not maintained referential integrity. Thats what relational datbases are for.
A better way to tacklt this would be to write a seperate page to view the details of a job. Simply pass the primary key in the querystring. It would make later changes to the web application much less of a headache-generating task.
Try something like this.
Ill explain, in the first page all you really need to pull back from the DB is the
list of jobs and the id number of that record (something that lets you tell one record from another, primary key, etc). Then all you have to do is list all the
jobs. For each job that is listed, you will set the primary key of that record
into a function that will open a new window for you. when you click on the
link it will call the showdetials and pass in the id number of the record that
was clicked. Now this will open a new window and pass the id through the
query string to page ShowDetials.asp?ID=?.
Now on the showDetials page you will get the id number from the query
stirng and then look up all the detials of that job using its ID number.
You will then execute that query which will pull back all the detials of that
job.
Now youll have to modify this code to get it to work for you, its just meant
to show you the way of the Force. Hope this helps.
Show Jobs Page
Code:
<script language=javascript>
function ShowDetails(nid){
window.open('ShowDetials.asp?ID='+nid , 'ShowDetails', 'width=400, height=500, resizalbe=no, scrollbars=yes);
}
</script>
<%
'For this SQL only pull the main data you will display to the user right now.
SQL = "SELECT ID, JOBTITLE FROM Jobs WHERE ? = ?"
rsGuestBook.Open SQL, adoConn
Do While Not rsGuestBook.EOF
%>
<a href="#" onclick="ShowDetails('<%=rsGuestBook("ID")%>');"><%=rsGuestBook("JobTitle")%></a>
<%
rsGuestBook.MoveNext
Loop
rsGuestBook.Close
%>
ShowDetials.asp
Code:
Dim ID
ID = Request.querystring("ID")
SQL = "SELECT (All the details about the job) FROM ? WHERE jobs.id_no = ' " & ID & " ' "
rsGuestBook.Open SQL, adoConn
if not objRS.EOF then
'List all the details of the job
else
'a problem occurred and we can not list the job detials
' some sort of error message
end if
rsGuestBook.close
Bookmarks