|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > How to check if a register for a specific field does not exist? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|