ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 11th, 2003, 05:53 AM
Danbr Danbr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Sertaozinho-SP
Posts: 45 Danbr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Question How to check if a register for a specific field does not exist?

Hi,

I have a database with two fields: product and photo. The page should display pictures of the product, which are on the photo field and if there is no picture (in this case there is no registers in the database) I need to display a message like "hey dude, no pics right now".

The code for it should be very simple:


<%while not rs.EOF%>
<br/>

<%if rs("photo") <> "" then%>
<img alt="foto"
src="c:\Work\Daniel\Web site\ServTec\Fotos1\<%=rs("photo")%>"
class="fotos"/>
<br/>
<%else
Document.Write("No pics this time dude")
end if%>

<%rs.MoveNext
wend
%>

However, whenever I test the page, I get no message saying "No pics this time dude".

Do I need to add registers in my database like

product photo
2344 NA

And then test for a string like "NA"

I thank you a lot!

Daniel

Reply With Quote
  #2  
Old November 11th, 2003, 07:09 AM
DarrenMBrink DarrenMBrink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Ohio
Posts: 30 DarrenMBrink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 6 sec
Reputation Power: 5
Send a message via AIM to DarrenMBrink
Why don't you switch your Document.write to Response.write, you should see something then.

A question I have for you is do you want that message to display if a certain products picture is not there? If so then the statement you have will not work. You'd have to use some kind of product identifer and check to see if that specific product has a photo and if so display that else display your message.

Reply With Quote
  #3  
Old November 11th, 2003, 07:15 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
2 things...

1) Make a Response.Write of your SQL Query *BEFORE* you execute it. This will ouput on the page the Query *you are about to execute*. Then copy/paste the SQL Query into your database and execute it.

Look at the results, are they what your expecting ???
I mean does the field photo actually has something inside?


2) Now the second thing is why are you using Document.Write? Shouldn't it be Response.Write?


To give you a code example try this:

<%
Dim strSql
Dim objConn
Dim objRst

strSql = "SELECT blah1, blah2 FROM MyTABLE"

'FOR DEBUG ONLY
Response.Write strSql
Response.End



'NOTE:Once you've copy/pasted the results of the *strSql*
'variable into your database and that it returns the results
'expected. You must comment the two lines under the
'FOR DEBUG ONLY section.

'Open connection to database
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "your_connection_string_goes_here"

'Execute the SQL Query
Set objRst = objConn.Execute(strSql)


'Now let's check to see if we first have any results...
If objRst.EOF Then

Response.Write "No records found for Query: " & strSql

'Close and free Recordset and Connection object
objRst.Close
Set objRst = nothing

objConn.Close
Set objConn = nothing

'Then stop the page from loading
Response.End



Else 'This means we have records inside our recordset

While NOT objRst.EOF

'Make the validation
If ("X" & Trim(objRst("photo")) = "X") Then

Response.Write "No photo dude!!!"

Else

Response.Write "<img src=""" & objRst("photo") & """>"

End If

objRst.MoveNext
Wend

'Close and free Recordset and Connection object
objRst.Close
Set objRst = nothing

objConn.Close
Set objConn = nothing


End If

%>


NOTE: This has not been tested but it should give you an idea...

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #4  
Old November 11th, 2003, 07:46 AM
Danbr Danbr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Sertaozinho-SP
Posts: 45 Danbr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
hey DarrenMBrink, Vlince

Thanks for the help.

I haven't pasted all the code before so it looked simpler.

But DarrenMBrink helped me with the line:

If objRst.EOF Then

I was looking for something similar and this property helped me.

Suppressing the database connections and other code, it will look like this:

<div id="rolagem">
<%if not rs.EOF then
while not rs.EOF%>
<br/>
<img alt="foto"
src="c:\Work\Daniel\Web site\ServTec\Fotos1\<%=rs("foto")%>"
class="fotos"/>
<br/>
<%rs.MoveNext
wend%>

<%else%>

<p>No pics dude!</p>

<%end if%>

</div>

Thanks a lot!

Daniel

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > How to check if a register for a specific field does not exist?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway