| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
Use between your <td> tags:
Code:
<% If Results("Subtitle") = "" Then
Response.Write Results("Author")
Else
Response.Write Results("SubTitle")
End If %>
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
Quote:
No, that's the whole problem: result is just not visible with script... You need the database to test? Regards, Bart Stens |
|
#6
|
||||
|
||||
|
If you don't mind. I can help you debug.
|
|
#7
|
|||
|
|||
|
I made a .zip-file of the files.
Regards. |
|
#8
|
||||
|
||||
|
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. |
|
#9
|
|||
|
|||
|
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) |
|
#10
|
|||
|
|||
|
Quote:
@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 |
|
#11
|
||||
|
||||
|
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 ![]() |
|
#12
|
||||
|
||||
|
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 |
|
#13
|
|||
|
|||
|
Quote:
Your African is good to understand for me, but I just also found out your English post, and YES, with that LIKE-function it won't display the record at all when the field is empty. I just putted a '_' in the empty databasefield to check if that was the error, and also put that in the script (= "_") and than it does work, but i won't fill all my empty database-fields. You are talking about a parameter-check and than build up the query. I'm really a newbie to .ASP and Access, but could you try to give me an example or code for that included in my code? Thnx 4 your good help! Regards, Bart |
|
#14
|
||||
|
||||
|
Hi,
i am glad you like my Afrikaans , I can almost understand everything in Dutch if I read it a couple of times, very similair to Afrikaans.Yes, that is what I mean, check the parameter's and build your query from that, here is a short example. Code:
Dim strSql
Dim strWhere
strSql = "SELECT * FROM Boeken WHERE "
If Titel <> "" Then
strWhere = strWhere & "Titel LIKE '%" & Titel & "%' "
end if
If Ondertitle <> "" Then
if strWhere = "" then
strWhere = strWhere & "Ondertitel LIKE '%" & Ondertitel & "%' "
else
strWhere = strWhere & "and Ondertitel LIKE '%" & Ondertitel & "%' "
end if
end if
If Auteur <> "" Then
if strWhere = "" then
strWhere = strWhere & "Auteur LIKE '%" & Auteur & "%' "
else
strWhere = strWhere & "and Auteur LIKE '%" & Auteur & "%' "
end if
end if
strSql = strSql & strWhere & ";"
Results.Open strSql
-->I added this code instead of
Results.Open "SELECT * FROM Boeken WHERE Categorie LIKE '" & Cat("Categorie") & "';", Conn
Hope this helps. |
|
#15
|
|||
|
|||
|
Quote:
YES, that does work, but one problem: when using the LIKE statement only for the value of 'Categorie', the whole search-form (zoek_form.asp) won't work anymore ofcourse Because it won't search in the database for LIKE's of the search-command.. how to change that? Regards, Bart |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > <% Response.Write %> into <% Response.Write %> |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|