Forums

ASP

This topic is locked

Simple ASP Problem Flummoxes Newbie

Posted 22 Dec 2006 14:05:56
1
has voted
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>&lt;!--#include virtual="/Connections/my_connections.asp" --&gt;
&lt;%
' ::::: 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
%&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;table width="800" border="0" align="center" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td width="378"&gt;All Companies &lt;/td&gt;
&lt;td width="422"&gt;Your Choices &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="center" valign="top"&gt;&lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;% while not rs_all.eof %&gt;
&lt;tr&gt;
&lt;td align="left"&gt;[&lt;a href="&lt;%= request.servervariables("script_name" & "?func=add&id=" & rs_all("id" %&gt;"&gt;ADD&lt;/a&gt;] &lt;%= rs_all("name" %&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;% rs_all.movenext
wend
rs_all.Close()
Set rs_all = Nothing
%&gt;
&lt;/table&gt;&lt;/td&gt;
&lt;td align="center" valign="top"&gt;&lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;% if rs_mine.eof then %&gt;
&lt;tr&gt;
&lt;td align="left"&gt;You've made no choices. &lt;/td&gt;
&lt;/tr&gt;
&lt;% else
while not rs_mine.eof
%&gt;
&lt;tr&gt;
&lt;td align="left"&gt;[&lt;a href="&lt;%= request.servervariables("script_name" & "?func=remove&id=" & rs_mine("id" %&gt;"&gt;REMOVE&lt;/a&gt;] &lt;%=(rs_mine.Fields.Item("name".Value)%&gt; - &lt;%=(rs_mine.Fields.Item("city".Value)%&gt;, &lt;%=(rs_mine.Fields.Item("state".Value)%&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;%
rs_mine.movenext
wend
rs_mine.Close()
Set rs_mine = Nothing

end if %&gt;
&lt;/table&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;</font id=code></pre id=code></font id=blue>

Edited by - daveblohm on 10 Jan 2007 21:02:25

Reply to this topic