Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with databases

Status
Not open for further replies.

johnsimpson

Programmer
Mar 28, 2006
60
GB
Hi Guys, got a couple of questions for you.

I'm making a basic content management backend for a website... its my first one but i am trying to learn as i go...

I want to display some information from my access database but i want to have the first row with a background of grey and the second row with a background of white - and then loop.

I have got it looping and displaying the code fine but not sure how to alternate.


Then the second question is, the client wants to have an image gallery in the admin side of the site. Basically with an upload button to add the image to the gallery but then from say within a news section they want to be able to browse the gallery and add the image to the article.

Ideally it would be a visual selection but if not maybe a drop down list?

your help and advise will be appreciated

thanks
J
 

[tt]mod[/tt] will help you determine odd and even (alternating) rows:
Code:
dim i 
for i = 1 to 10
  if i mod 2 > 0 then
    response.write("odd")
  else
    response.write("even")
  end if
next

Not sure that your second question is actually a question.. ;-)

You can do it in many different ways - you could create a div that you make visible when the user wants to see the selection of images, and then dynamically load the images into the div (with auto-scroll so it doesn't hog the page) - you can either do this by getting a list of the images from a directory (FSO) or from a database (ADO) - whichever you prefer - and adding them to the div as images inside anchor links (<a>). This could then send a GET request (url within the link) to a page that adds or updates the image to your database or relevant page (however you've got it set up). You can of course use a popup window, or play with the div idea with scrolling to create a faux combo/dropdown box with images.

A vague answer, but that's the result of a vague 'question' !

If you have more specific questions feel free to post back.



A smile is worth a thousand kind words. So smile, it's easy! :)
 
ok... sorry should have thought it through...

firstly, forgive me for being dim, but as i said its my first time... where would i put the code above? Currently the code for presenting the data is as follows:

<%
sqltxt="select * from tblMeetings order by MeetingDate asc"
objRS.Open sqltxt,constr

if not objRS.EOF then
do while not objRS.EOF
%>
<tr bgcolor="#cccccc">
<td height="20" class="tablecontents"><%response.write objRS("Title")%></td>
<td height="20" class="tablecontents"><%response.write dispshortdate(objRS("MeetingDate"))%></td>
<td height="20" class="tablecontents"><%response.write objRS("Location")%></td>
<td height="20" class="tablecontents" align="center"><input name="checkbox" type="checkbox" value="checkbox" <%response.write objRS("Minutes") %> disabled="disabled"></td>
<td height="20" class="tablecontents"><a href="meetings_edit.asp?userid=<%response.write UserID%>&newsid=<%response.write objRS("NewsID")%>" target="_blank">Edit details</a></td>
</tr>
<%
objRS.Movenext
loop
else
%>
<tr bgcolor="#cccccc">
<td height="20" class="tablecontents">Awaiting meeting</td>
<td height="20" class="tablecontents"></td>
<td height="20" class="tablecontents"></td>
<td height="20" class="tablecontents" align="center"></td>
<td height="20" class="tablecontents"></td>
</tr>
<%
end if
objRS.Close
%>


and then... the question from before:

I want the user to have a facility to upload images to their website and store the image reference / information in the database.

Then i want the user to be able to select an image for use on the page they are administrating, but i want them to be visually select the image they want a popup with all the images that have uploaded from before showing the full image but scaled down on the page so they are like thumbnails would be ideal.
When the user selects the image from the popup, the popup can close and a reference to the image added to the rest of the information about the news article. Then they click submit to submit the whole article which will have the image in...

does that make sense? im trying to explain what i want to do so you might be able to point me in the right direction?

thanks for your help
John
 
John,

Why don't you have a go at using the code 'example' I provided for the first question in your code - if you think about it logically, it is checking whether the current record is an even numbered record or an odd numbered record. Therefore you need to look at what similar loops you are doing and add the check (if / mod statement) inside that loop - making sure that the i var is defined outside of the loop but updated on each iteration.

Q2. You seem to be asking for an entire solution for your images, so you are better off reading through some tutorials - there are thousands out there to choose from, Google will help you find them. To get you started, here are some links:

1. File Upload:

2. Image Resize: Unfortunately you cannot do this with Classic ASP alone, you will need to use a component that will do the resizing for you - or you can build it yourself (but somehow I don't think this is for you)
or
(a paid for solution)
(not true resizing - you will just proportion images, so the size will remain the same)
or a list:

3. Database Inserts/Updates:

4. Database Selects:

5. Javascript Forum: forum216 (for managing your popups etc)

Hope that helps.


A smile is worth a thousand kind words. So smile, it's easy! :)
 
You don't need a counter and mod to determine odd/even rows, all you need is a bistate variable. A boolean works very well for this. Here's an example:
Code:
greyrow = true
do while not rs.EOF
   if greyrow then bg = "grey" else bg = "white"
%>
<tr style="background-color:<%=bg%> ...>
...
<%
   greyrow = not greyrow
   rs.MoveNext
loop
If you need to substitute a value into the html in order to pass a value to a javascript function to highlight the row onmouseover and return it to it's original background color onmouseout, a boolean won't work well, since VBS uses True/False for the values, and javascript uses true/false (case difference). In that case you can initialize greyrow to -1, and multiply it by -1 instead of using not. Then check for < 0 for gray, > 0 for white. That value will substitute and pass easily. Here's an example of this:
Code:
<script type="text/javascript>
function HighlightRow(row) {
   row.style.backgroundColor = "yellow";
}
function UnhighlightRow(row,greyrow) {
   if ( greyrow < 0 )
      row.style.backgroundColor = "grey";
   else
      row.style.backgroundColor = "white";
}
</script>
...
<%
greyrow = -1
do while not rs.EOF
   if greyrow < 0 then bg = "grey" else bg = "white"
%>
<tr style="background-color:<%=bg%> onmouseover="HighlightRow(this);" onmouseout="UnhighlightRow(this,<%=greyrow%>);" ...>
...
<%
   greyrow = greyrow * -1
   rs.MoveNext
loop
%>


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top