Forums
This topic is locked
Simple ASP Problem Flummoxes Newbie
22 Dec 2006 14:05:56 allen bad posted:
<font face='Arial'></font id='Arial'>Newbie question alert - walk away if irritated! - Sorry....
Situation:
Page displays a list of companies, with info such as address, phone number, etc. These information is read from table_companyinfo, where the Primary Key (Access Database) is a field called "ID".
User chooses companies he likes, and the page writes his choices into a new table (table_mylist), writing each compay's unique "ID" into the table.
The next time this user logs back on, he can call up a page which displays all his chosen companies, complete with all the companies' details (as in table_companyinfo).
How can I do this? When I call up the table_mylist to access the company IDs, how can I then transfer the ID into the filter for table_companyinfo so that the rest of the company's detail can be displayed?
Hope that was clear, cause I am stuck...
allenbad
Replies
Replied 10 Jan 2007 21:00:21
10 Jan 2007 21:00:21 dave blohm replied:
OK...I <i>think</i> I understand what you're looking for. I've written a down and dirty one-paged app that carries out the tasks you've outlined. The code listed below shows all the names of all the companies in the table_companyinfo with a link that reads ADD on the left side of the page and all the company info for the companies the user has chosen on the right. I have no idea what you are doing for as far as login so I just set the variable that represents the logged in user's id manually. If the user clicks on ADD next to a company name that company is added to the users list on the right. In the user's list on the right next to each chosen company is a link that reads REMOVE...bet you can guess what this does.
Anyway, like I said...I <i>think</i> this is what you're looking for. Very basic. No error checking so you can add the same company to the chosen list multiple times.
Hope this helps...
- Doc
CODE:
<font color=blue>
<pre id=code><font face=courier size=2 id=code><!--#include virtual="/Connections/my_connections.asp" -->
<%
' ::::: SET THE USER ID VALUE FOR THE LOGGED IN USER...IN THE REAL WORLD THIS
' ::::: WOULD LIKELY BE A COOKIE OR SESSION VARIABLE
var_loggedin_user_id = 1
' ::::: PERFORM THE INSERT OR DELETE FROM THE TABLE_MYLIST TABLE
select case(request.querystring("func")
case "add"
Set add_cmd = Server.CreateObject ("ADODB.Command"
add_cmd.ActiveConnection = MM_my_connections_STRING
add_cmd.CommandText = "insert into table_mylist (user_id,company_id) values (" & cint(var_loggedin_user_id) & "," & cint(request.querystring("id") & ""
add_cmd.Execute
set add_cmd = nothing
response.redirect request.servervariables("script_name"
case "remove"
Set remove_cmd = Server.CreateObject ("ADODB.Command"
remove_cmd.ActiveConnection = MM_my_connections_STRING
remove_cmd.CommandText = "delete from table_mylist where user_id = " & cint(var_loggedin_user_id) & " and company_id = " & cint(request.querystring("id")
remove_cmd.Execute
set remove_cmd = nothing
response.redirect request.servervariables("script_name"
end select
' ::::: GET ALL THE COMPANY NAMES
Set rs_all_cmd = Server.CreateObject ("ADODB.Command"
rs_all_cmd.ActiveConnection = MM_my_connections_STRING
rs_all_cmd.CommandText = "SELECT * FROM usr_website.table_company_info order by name"
rs_all_cmd.Prepared = true
Set rs_all = rs_all_cmd.Execute
' ::::: GET THE NAMES INFO OF THE COMPANIES THE USER HAS ADDED TO THEIR LIST
Set rs_mine_cmd = Server.CreateObject ("ADODB.Command"
rs_mine_cmd.ActiveConnection = MM_my_connections_STRING
rs_mine_cmd.CommandText = "SELECT table_company_info.* FROM table_company_info INNER JOIN table_mylist ON table_company_info.id = table_mylist.company_id WHERE (table_mylist.user_id = " & cint(var_loggedin_user_id) &""
rs_mine_cmd.Prepared = true
Set rs_mine = rs_mine_cmd.Execute
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="378">All Companies </td>
<td width="422">Your Choices </td>
</tr>
<tr>
<td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<% while not rs_all.eof %>
<tr>
<td align="left">[<a href="<%= request.servervariables("script_name" & "?func=add&id=" & rs_all("id" %>">ADD</a>] <%= rs_all("name" %></td>
</tr>
<% rs_all.movenext
wend
rs_all.Close()
Set rs_all = Nothing
%>
</table></td>
<td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<% if rs_mine.eof then %>
<tr>
<td align="left">You've made no choices. </td>
</tr>
<% else
while not rs_mine.eof
%>
<tr>
<td align="left">[<a href="<%= request.servervariables("script_name" & "?func=remove&id=" & rs_mine("id" %>">REMOVE</a>] <%=(rs_mine.Fields.Item("name".Value)%> - <%=(rs_mine.Fields.Item("city".Value)%>, <%=(rs_mine.Fields.Item("state".Value)%></td>
</tr>
<%
rs_mine.movenext
wend
rs_mine.Close()
Set rs_mine = Nothing
end if %>
</table></td>
</tr>
</table>
</body>
</html></font id=code></pre id=code></font id=blue>
Edited by - daveblohm on 10 Jan 2007 21:02:25
Anyway, like I said...I <i>think</i> this is what you're looking for. Very basic. No error checking so you can add the same company to the chosen list multiple times.
Hope this helps...
- Doc
CODE:
<font color=blue>
<pre id=code><font face=courier size=2 id=code><!--#include virtual="/Connections/my_connections.asp" -->
<%
' ::::: SET THE USER ID VALUE FOR THE LOGGED IN USER...IN THE REAL WORLD THIS
' ::::: WOULD LIKELY BE A COOKIE OR SESSION VARIABLE
var_loggedin_user_id = 1
' ::::: PERFORM THE INSERT OR DELETE FROM THE TABLE_MYLIST TABLE
select case(request.querystring("func")
case "add"
Set add_cmd = Server.CreateObject ("ADODB.Command"
add_cmd.ActiveConnection = MM_my_connections_STRING
add_cmd.CommandText = "insert into table_mylist (user_id,company_id) values (" & cint(var_loggedin_user_id) & "," & cint(request.querystring("id") & ""
add_cmd.Execute
set add_cmd = nothing
response.redirect request.servervariables("script_name"
case "remove"
Set remove_cmd = Server.CreateObject ("ADODB.Command"
remove_cmd.ActiveConnection = MM_my_connections_STRING
remove_cmd.CommandText = "delete from table_mylist where user_id = " & cint(var_loggedin_user_id) & " and company_id = " & cint(request.querystring("id")
remove_cmd.Execute
set remove_cmd = nothing
response.redirect request.servervariables("script_name"
end select
' ::::: GET ALL THE COMPANY NAMES
Set rs_all_cmd = Server.CreateObject ("ADODB.Command"
rs_all_cmd.ActiveConnection = MM_my_connections_STRING
rs_all_cmd.CommandText = "SELECT * FROM usr_website.table_company_info order by name"
rs_all_cmd.Prepared = true
Set rs_all = rs_all_cmd.Execute
' ::::: GET THE NAMES INFO OF THE COMPANIES THE USER HAS ADDED TO THEIR LIST
Set rs_mine_cmd = Server.CreateObject ("ADODB.Command"
rs_mine_cmd.ActiveConnection = MM_my_connections_STRING
rs_mine_cmd.CommandText = "SELECT table_company_info.* FROM table_company_info INNER JOIN table_mylist ON table_company_info.id = table_mylist.company_id WHERE (table_mylist.user_id = " & cint(var_loggedin_user_id) &""
rs_mine_cmd.Prepared = true
Set rs_mine = rs_mine_cmd.Execute
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="378">All Companies </td>
<td width="422">Your Choices </td>
</tr>
<tr>
<td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<% while not rs_all.eof %>
<tr>
<td align="left">[<a href="<%= request.servervariables("script_name" & "?func=add&id=" & rs_all("id" %>">ADD</a>] <%= rs_all("name" %></td>
</tr>
<% rs_all.movenext
wend
rs_all.Close()
Set rs_all = Nothing
%>
</table></td>
<td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<% if rs_mine.eof then %>
<tr>
<td align="left">You've made no choices. </td>
</tr>
<% else
while not rs_mine.eof
%>
<tr>
<td align="left">[<a href="<%= request.servervariables("script_name" & "?func=remove&id=" & rs_mine("id" %>">REMOVE</a>] <%=(rs_mine.Fields.Item("name".Value)%> - <%=(rs_mine.Fields.Item("city".Value)%>, <%=(rs_mine.Fields.Item("state".Value)%></td>
</tr>
<%
rs_mine.movenext
wend
rs_mine.Close()
Set rs_mine = Nothing
end if %>
</table></td>
</tr>
</table>
</body>
</html></font id=code></pre id=code></font id=blue>
Edited by - daveblohm on 10 Jan 2007 21:02:25