Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

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 ASP Free Forums Sponsor:
  #1  
Old January 11th, 2005, 12:21 PM
stensol stensol is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Netherlands
Posts: 28 stensol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 10 sec
Reputation Power: 0
Lightbulb <% Response.Write %> into <% Response.Write %>

Hi guys,

Notice: I'm from The Netherlands, and my English ain't that well, sorry 4 that

I started learning .ASP one week ago, and now I already wrote my own add/modify/delete bookcatalog.

Ofcourse that process didn't go without any problems, I have the following problem now:

I've HTML-cells (<td></td>) in which I want to print values from the database by adding the asp-code "Response.Write". So it now looks like:
*<td> <% = Results("Subtitle") %> </td>*
That piece of code works fine: gets values from pre-defined recordset connected to the Access-database.

But now I want to change that piece of code, so that when the value "Subtitle" in the database is empty (= ""), the code will be changed into:
*<td> <% = Results("Author") %> </td>*


Someone who could help? Shouldn't be that difficult I guess?

Thanx for your help...

Regards,
Bart Stens, Netherlands

Reply With Quote
  #2  
Old January 11th, 2005, 12:27 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 22 h 25 m 10 sec
Reputation Power: 1488
Use between your <td> tags:
Code:
<% If Results("Subtitle") = "" Then
    Response.Write Results("Author")
      Else
   	Response.Write Results("SubTitle")
      End If %>

Reply With Quote
  #3  
Old January 11th, 2005, 12:56 PM
stensol stensol is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Netherlands
Posts: 28 stensol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 10 sec
Reputation Power: 0
Unhappy won't work

Thanx Lewy, think that code is ok, but my whole code ain't, so below I post it. I marked the important points with red font.

Code:
<%
Set Conn = Server.CreateObject("ADODB.Connection")
		Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
		Conn.Open Server.MapPath("Books.mdb")

Titel = replace(Request("txtTitel"), " ", "%")
Ondertitel = replace(Request("txtOndertitel"), " ", "%")
Auteur  = replace(Request("txtAuteur"), " ", "%")
Jaar = replace(Request("txtJaar"), " ", "%")
Jaargang = replace(Request("txtJaargang"), " ", "%")
Uitgever = replace(Request("txtUitgever"), " ", "%")
Bijzonderheden = replace(Request("txtBijzonderheden"), " ", "%")

Set Cat = Server.CreateObject("ADODB.recordset")
		Cat.Open "SELECT DISTINCT Categorie FROM Boeken WHERE Categorie LIKE '%" & Request("cmbCategorie") & "%';", Conn
		'Cat.Open "SELECT Categorie FROM Boeken;", Conn
%>


<%
 Call Cat.MoveFirst()
 While Not Cat.EOF

 Set Results = Server.CreateObject("ADODB.recordset")
     Results.Open "SELECT * FROM Boeken WHERE Titel LIKE '%" & Titel & "%' and Ondertitel LIKE '%" & Ondertitel & "%' and Auteur  LIKE '%" & Auteur  & "%' and Jaar LIKE '%" & Jaar & "%' and Jaargang LIKE '%" & Jaargang & "%' and Uitgever LIKE '%" & Uitgever & "%' and Bijzonderheden LIKE '%" & Bijzonderheden & "%' and Categorie LIKE '" & Cat("Categorie") & "' and Nummer LIKE '%" & Nummer & "%';", Conn

 Call Results.MoveFirst()
     if Results("Titel") = "" then
     else
%>

	
h4><% Response.Write(cat("Categorie")) %></h4>	


<%
 While Not Results.EOF
%>

	<tr>
   	 <td width="8%" valign="top"><font color="#960000"><%=Results("Nummer")%><font color="#960000"></td>
 	 <td width="40%" valign="top"><a href="index.asp?Pagina=boek&Nummer=<%=Results("Nummer")%>" target="_self"><%=Results("Titel")%></a><br><br></td>
  	 <td width="32%" valign="top"><%=Results("Ondertitel")%></a><br><br></td>
 	 <td width="20%" valign="top"><% If Results("Auteur") = "" Then Response.Write Results("Jaargang") Else Response.Write Results("Auteur") End if %></td>
 	 </tr>

<%
 Call Results.MoveNext()
 Wend
%>

<%
   end if
 Call Cat.MoveNext()
 Wend
 Results.Close
%>



Problem is: search results do appear, but the records of which the field "Auteur" in the Access database is empty, just don't appear as a result at all with that code?!?

Plz. help .. (can't find it in my learning .ASP book )

Regards,
Bart Stens

Reply With Quote
  #4  
Old January 11th, 2005, 01:42 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 22 h 25 m 10 sec
Reputation Power: 1488
Are you getting any error messages? If so, post them.
Try the following instead of your code:
Code:
 
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.Open Server.MapPath("Books.mdb")
Set Results = Server.CreateObject("ADODB.recordset")
Set Cat = Server.CreateObject("ADODB.recordset")
Cat.Open "SELECT DISTINCT Categorie FROM Boeken WHERE Categorie LIKE '%" & Request("cmbCategorie") & "%';", Conn
While Not Cat.EOF
	 Results.Open "SELECT * FROM Boeken WHERE Titel LIKE '%" & Titel & "%' and Ondertitel LIKE '%" & Ondertitel & "%' and Auteur LIKE '%" & Auteur & "%' and Jaar LIKE '%" & Jaar & "%' and Jaargang LIKE '%" & Jaargang & "%' and Uitgever LIKE '%" & Uitgever & "%' and Bijzonderheden LIKE '%" & Bijzonderheden & "%' and Categorie LIKE '" & Cat("Categorie") & "' and Nummer LIKE '%" & Nummer & "%';", Conn
	 If Results("Titel") = "" Then
		 %><h4><% Response.Write(cat("Categorie")) %></h4><%
	 Else
		 While Not Results.EOF
		 %>
			 <tr>
				<td width="8%" valign="top"><font color="#960000"><%=Results("Nummer")%><font color="#960000"></td>
				<td width="40%" valign="top"><a href="index.asp?Pagina=boek&Nummer=<%=Results("Nummer")%>" target="_self"><%=Results("Titel")%></a><br><br></td>
				<td width="32%" valign="top"><%=Results("Ondertitel")%></a><br><br></td>
				<td width="20%" valign="top"><% If Results("Auteur") = "" Then Response.Write Results("Jaargang") Else Response.Write Results("Auteur") End if %></td>
			</tr>
		 <%
		 Results.MoveNext
		 Wend
		End if
		Results.Close
	 Cat.MoveNext
Wend
%>
 

Last edited by lewy : January 11th, 2005 at 01:53 PM.

Reply With Quote
  #5  
Old January 11th, 2005, 01:53 PM
stensol stensol is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Netherlands
Posts: 28 stensol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by lewy
Are you getting any error messages? If so, post them.


No, that's the whole problem: result is just not visible with script...

You need the database to test?

Regards,
Bart Stens

Reply With Quote
  #6  
Old January 11th, 2005, 01:55 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 22 h 25 m 10 sec
Reputation Power: 1488
If you don't mind. I can help you debug.

Reply With Quote
  #7  
Old January 11th, 2005, 02:01 PM
stensol stensol is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Netherlands
Posts: 28 stensol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 10 sec
Reputation Power: 0
Exclamation .zip

I made a .zip-file of the files.

Regards.
Attached Files
File Type: zip search.zip (20.4 KB, 305 views)

Reply With Quote
  #8  
Old January 11th, 2005, 02:08 PM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
Hi,

sorry 2 bother, but was wondering if you could check this out before you go ahead

If you use the like statement, and you don't insert a value, it wont return the records from the database if there is no value in the database field?

ie
Code:
select * from table where name like '%%'

won't return a value if the database fields are empty, because if you use a empty like, it only brings it back if there is a value in the field?

Just a though, I had a similair problem before.

Reply With Quote
  #9  
Old January 11th, 2005, 02:11 PM
stensol stensol is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Netherlands
Posts: 28 stensol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 10 sec
Reputation Power: 0
Short explanation cause most of script is in "Dutch" :

Books.mdb (Access Database)
> use table 'Boeken'
field 'Auteur'
field 'Druk'

** Want to view the value 'Druk' into the "Response.Write" when the field 'Auteur' is empty.


zoek_form.asp (search-form)
not neccesary for debugging


zoek_get.asp (search-script)
to test for the pre-made "empty record" 'Nummer' 154,
zoek_get.asp?cmbCategorie=plaatjesalbums
(should give 3 results: Nummer 154,155,156)

Reply With Quote
  #10  
Old January 11th, 2005, 02:18 PM
stensol stensol is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Netherlands
Posts: 28 stensol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by nofriends
Hi,

sorry 2 bother, but was wondering if you could check this out before you go ahead

If you use the like statement, and you don't insert a value, it wont return the records from the database if there is no value in the database field?

ie
Code:
select * from table where name like '%%'

won't return a value if the database fields are empty, because if you use a empty like, it only brings it back if there is a value in the field?

Just a though, I had a similair problem before.


@Nofriends:

my English ain't that good to understand your post. Do you have a question or do you suggest that the LIKE disrupts the code? and that you don't have an answer cause it's a though problem?

I was thinkin' that maybe set an extra recordset could help???

Regards, Bart

Reply With Quote
  #11  
Old January 11th, 2005, 02:26 PM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
verstaan jy dit beter?

in Afrikaans, almost the same
Wat ek bedoel is, as jy die LIKE gebruik, en daar is geen PARAMATER nie, sal dit nie vir jou 'n record terug bring as die veld in die database leeg is nie, want die like soek 'n value.

in English: :
What I mean is, if you use LIKE and the parameter is empty, it wont return a value if the field in the database is empty.

I ussually check if the paramater is empty and build up the query according to that.

Don't know if that is your problem, just wondering if it won't help

Reply With Quote
  #12  
Old January 11th, 2005, 02:33 PM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101943 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
Hi,

i changed the sql statement to:
Code:
Results.Open "SELECT * FROM Boeken WHERE Categorie LIKE '" & Cat("Categorie") & "';", Conn


and used this url
Code:
http://localhost/search/zoek_get.asp?cmbCategorie=plaatjesalbums


and it brought back all 3 results.

So I think it has to do with the like statements

Reply With Quote