Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - if statement problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

if statement problem

 Post Reply Post Reply Page  12>
Author
Corky View Drop Down
Newbie
Newbie


Joined: 07 January 2004
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote Corky Quote  Post ReplyReply Direct Link To This Post Topic: if statement problem
    Posted: 07 January 2004 at 10:37am

Hello all,

I know I must be doing something stupid here but it's driving me crazy.  I'm trying to create a report through an asp page querying an access database which is fine until I have tried to create some grouping - listing the group name only once on the report. 

I'm trying to use the line <% if  objrs(i) <> grouping then %> to detect if the grouping name needs to be input into the report or not however this is always returning true and the next bit of code is always being executed...

 any help is much  appreciated. 

The full code is: -

<%

dim grouping

grouping = "first"

 

while not objrs.eof

%>

   <TR>

<% For i = 0 to objrs.fields.count - 1%>

 

<% Select Case i %>

                 <% Case "0" %>

                                  <% if  objrs(i) <> grouping then %>

                                                   <TD VALIGN=TOP><B><% = objrs(i) %></B></TD>

                                                    <% grouping = objrs.fields("Location").value %>

                                                    </tr>

                                                    <tr>

                                  <% End if %>

                 <% Case "1" %>

                                  <TD VALIGN=TOP ALIGN=LEFT><% = objrs(i) %></TD>

                                  <td></td>

                 <% Case "2" %>

   

Back to Top
aalavar View Drop Down
Groupie
Groupie


Joined: 08 December 2003
Status: Offline
Points: 46
Post Options Post Options   Thanks (0) Thanks(0)   Quote aalavar Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2004 at 11:49am

I don't know if this is related or not, but shouldn't the case statement not contain quotes?  If you are trying to compare integers, then it should be: <% Case 1 %>.

As far as the other problem, what kind of record is being returned with objrs?  i.e. show me the list of what one record being returned contains (id,name,date,etc.), and in what order they are being returned from the database.

Back to Top
Corky View Drop Down
Newbie
Newbie


Joined: 07 January 2004
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote Corky Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2004 at 12:07pm

Thanks for the reply

the fields and field values being returned in this order: -

fields

Location,ID,Title,InsuranceValue,PurcahsePrice

Values sample

Room 9,1,happy valley,3500,3500

Room10,2,rounding the copelands,300,200

probably should of included the SQL statement I was using: -

 

strSQL="SELECT Asset_Register_Heritage.Location,Asset_Register_Heritage.ID, Asset_Register_Heritage.Title,Asset_Register_Heritage.Insura nce,Asset_Register_Heritage.purchaseprice FROM Asset_Register_Heritage ORDER BY Asset_Register_Heritage.Location,Asset_Register_Heritage.ID"

I have put into the code  the statement <%=grouping%> --- <%objrs(i)%> just after the case 0 to see what values are being fired out each time and the variables being stored are correct as in when I want the statement to be false I'm getting

Room 9 --- Room9

which should ignore the td line but its not...

likewise when it comes accross a new value in the table and I want this to be represented this statement does all the right things i.e.

Room 9 --- Room 10

It just doesn't seem to be working in the if statement

 

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2004 at 12:10pm

Sorry don't have time to fully help you, but some tips:

<% and %> are called ASP blocks, they slow the page loading time down.  In your code you have for example:

                                  <% End if %>

                 <% Case "1" %>

 

This can be changed to:

<%
  End if
  Case "1"
%>

Back to Top
Corky View Drop Down
Newbie
Newbie


Joined: 07 January 2004
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote Corky Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2004 at 12:14pm
Thanks for the tips Gullanian but I really only typed in the extra blocks so it was easier to view on the forum
Back to Top
aalavar View Drop Down
Groupie
Groupie


Joined: 08 December 2003
Status: Offline
Points: 46
Post Options Post Options   Thanks (0) Thanks(0)   Quote aalavar Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2004 at 12:18pm

Room 9 <> Room9

They are different strings... Try changing your compare to "Room 9"

Back to Top
Corky View Drop Down
Newbie
Newbie


Joined: 07 January 2004
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote Corky Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2004 at 12:21pm
Sorry Room 9 and Room9 was just a typo on my behalf.
Back to Top
aalavar View Drop Down
Groupie
Groupie


Joined: 08 December 2003
Status: Offline
Points: 46
Post Options Post Options   Thanks (0) Thanks(0)   Quote aalavar Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2004 at 12:26pm

Ok, let's try something else, do this and look at the output:

*<%=grouping%>* --- *<%objrs(i)%>*

I'm wondering if there are any extra spaces in your database object...  If not this should show up as *Room 9* --- *Room 9*.  If it shows up as *Room 9* --- *Room 9   * that is the problem.  I'll keep looking if you want to check that out.

Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.