|
 |
asp_databases thread: conveting recordset into series of chechboxes
Message #1 by "Chirag Shah" <chiragiit@y...> on Tue, 4 Feb 2003 03:22:43
|
|
My database query is returning recorset as Year 1997,1999, 2000, 2001
On my HTML form i am having series of checkboxes for different year
for eg.
<input type="checkbox" name="Year" value="1997">
<input type="checkbox" name="Year" value="1998">
<input type="checkbox" name="Year" value="1999">
<input type="checkbox" name="Year" value="2000">
<input type="checkbox" name="Year" value="2001">
<input type="checkbox" name="Year" value="2002">
<input type="checkbox" name="Year" value="2003">
for each *year* return by my recordset I want that checkbox to be checked.
so for eg. if query returns year 2002,2003 then i want to those checkboxes
checked. Any easier way to *Loop* through recordset.
Thanks in advance
Message #2 by "Philhouse" <spam@t...> on Tue, 4 Feb 2003 06:31:09
|
|
I would think the easiest way of doing that would be by entering the years
into a definition table in the database. What you could do then is do a
left join between the definition table and the table holding your series
of years. For example:
Tables:
defn_year_tb
year_id (PK)
desc_tx
data_value_tb
value_id (PK)
year_id (FK)
Query:
SELECT
ISNULL(v.value_id, 0) AS value_id
,y.desc_tx
FROM
defn_year_tb AS y
LEFT JOIN data_value_tb AS v ON y.year_id=v.year_id
ORDER BY
y.desc_tx
Then you could build the checkboxes like so:
<%
do until oRS.EOF%>
<input type="checkbox" name="Year" value="<%=oRS("desc_tx")%>"<%if oRS
("value_id") <> "0" then response.write " checked"%>>
<% oRS.MoveNext
loop
%>
Hope that helps.
Clear Skies
> My database query is returning recorset as Year 1997,1999, 2000, 2001
O> n my HTML form i am having series of checkboxes for different year
f> or eg.
<> input type="checkbox" name="Year" value="1997">
<> input type="checkbox" name="Year" value="1998">
<> input type="checkbox" name="Year" value="1999">
<> input type="checkbox" name="Year" value="2000">
<> input type="checkbox" name="Year" value="2001">
<> input type="checkbox" name="Year" value="2002">
<> input type="checkbox" name="Year" value="2003">
> for each *year* return by my recordset I want that checkbox to be
checked.
s> o for eg. if query returns year 2002,2003 then i want to those
checkboxes
c> hecked. Any easier way to *Loop* through recordset.
>
T> hanks in advance
|
|
 |