I have a quick question about setting up a table after you have queried an Access database. I have already setup my database as well as my asp file and I have it pulling all of the data in and then displaying it properly in a table. I've done that plenty before but just in very vanilla tables. What I was trying to do was have the table alternate background colors each row.I obviously know how to do this when manually creating an html table where I know the set number of rows. So I already have my alternating <tr> classes set. What I am trying to do atm is have the file check the autonumbered ID value from the Access database and, based on whether that value is even or odd create the new row for the set of entries using one of the two <tr> classes.What I have right now is this: (only posting the area right around the table)<table id="training"><tr> <th>Date</th> <th>Training Title</th> <th>Presenter</th></tr><%Set rsTraining = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT tblLunchandLearns.Date, tblLunchandLearns.Title, tblLunchandLearns.Presenter, tblLunchandLearns.ID FROM tblLunchandLearns ORDER BY DATE DESC;" rsTraining.Open strSQL, adoCon%><%'Loop through the recordsetDo While not rsTraining.EOF%><% If rsTraining("ID")%2=0 Then%><tr><td><% Response.Write (rsTraining("Date")) %> </td><td><% Response.Write (rsTraining("Title")) %></td><td><% Response.Write (rsTraining("Presenter")) %></td></tr><%Else%><tr class="alt"><td><% Response.Write (rsTraining("Date")) %> </td><td><% Response.Write (rsTraining("Title")) %></td><td><% Response.Write (rsTraining("Presenter")) %></td></tr><% End if rstraining.movenext Loop rstraining.close%> </table>Obviously the %2=0 or %2<>0 isn't correct here because I get the error:Microsoft VBScript compilation error '800a0408'Invalid character/buildingsystems/lunch and learns/training3.asp, line 74If rsTraining("ID")%2=0 Then-------------------^It had been awhile since I had done anything checking odd vs even and that was just my lame attempt at pulling something from memory. Anyone know the correct way for me to check the odd/even status of the current record ID?[Edited on March 17, 2011 at 1:58 PM. Reason : .]
3/17/2011 1:47:16 PM
PS, a counter scenario here would be fine as well.
3/17/2011 2:30:10 PM
I don't know ASP, but google says modulus syntax is "Mod"
If rsTraining("ID") Mod 2=0 Then
If rsTraining("ID")%2=0 Then-------------------^
3/17/2011 2:46:32 PM
Awesome, thanks a lot. I did know the % sign was the problem here I just wasn't sure what to put in its place. I googled a bunch of stuff but didn't know to google "modulus syntax." Really appreciate the help.
3/17/2011 3:05:26 PM
% is the code-block delimiter in ASP, like
HTML CODE<% ASP CODE %>HTML CODE
3/17/2011 3:11:02 PM
^^think "asp operators"finding a good page on operators should tell you syntax for arithmetic, comparison, concatenation. it helps a lot when you're learning a new language.[I wish questions on stackoverflow were this easy. On SO, I oscillate between 1) feeling like a complete idiot on any subject 2) being seconds too late 3) answering the user's question correctly and then having them ignore the entire thing][Edited on March 17, 2011 at 3:23 PM. Reason : asdf]
3/17/2011 3:20:36 PM
^thanks ^^ I use VB in excel but never anything like this. I'm not a programmer by any means though. Only programming class I took in college was one semester of FORTRAN freshman year. I'm just a dabbler.
3/17/2011 3:36:59 PM
remember, you can write FORTRAN in any language...just don't
3/17/2011 4:15:24 PM