CalledToArms All American 22025 Posts user info edit post |
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 recordset Do 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 74
If 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 |
CalledToArms All American 22025 Posts user info edit post |
PS, a counter scenario here would be fine as well. 3/17/2011 2:30:10 PM |
EuroTitToss All American 4790 Posts user info edit post |
I don't know ASP, but google says modulus syntax is "Mod"
If rsTraining("ID") Mod 2=0 Then http://www.tizag.com/aspTutorial/aspOperators.php
also, the errors seem pretty helpful about showing you which column you should look at. here, it's pointing to %
If rsTraining("ID")%2=0 Then -------------------^
[Edited on March 17, 2011 at 2:52 PM. Reason : asdfasdf]3/17/2011 2:46:32 PM |
CalledToArms All American 22025 Posts user info edit post |
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 |
lewisje All American 9196 Posts user info edit post |
% is the code-block delimiter in ASP, like HTML CODE <% ASP CODE %> HTML CODE so obvs. % can't have the "modulus" usage that it has in PHP, Javascript, and most other languages...
learn VB n00b3/17/2011 3:11:02 PM |
EuroTitToss All American 4790 Posts user info edit post |
^^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 |
CalledToArms All American 22025 Posts user info edit post |
^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 |
lewisje All American 9196 Posts user info edit post |
remember, you can write FORTRAN in any language...just don't 3/17/2011 4:15:24 PM |