PDA

View Full Version : Need help urgently...


helLO
04-06-2003, 08:17 AM
I got a couples of problems to ask urgently...

I got a DSN called Cart. I got a table called Product with 3 columns, each named Cat, Description and Price respectively...

In the Cat column, i had datas called FOOD.
How can i called the Cat column with all the datas named "FOOD" to display the Description and Price?

I wrote this but didn't work... The datas are not selected and displayed...

<%
'Declare variables
Dim Connect
Dim Record
'Create objects
Set Connect = Server.CreateObject("ADODB.Connection")
Set Record = Server.CreateObject("ADODB.Recordset")
'Open connection and run query
Connect.Open "Cart"
Record.Open "SELECT * FROM product WHERE Cat='&Food&'",Connect
%>

<table border=1 align=center>
<tr><th>Description</th>
<th>Price($)</th>
</tr>

<%While Not Record.EOF%>

<tr align=center>
<td><%Response.Write(Record("Description")&"")%></td>
<td><%Response.Write(Record("Price") & "<br>")%></td>
<%Record.MoveNext%>

<%Wend%>
</table>

<%Record.Close
Connect.Close
Set Record=Nothing
Set Connect=Nothing
%>

Next, I would like to know how can i store images in the databases as in to set the path of the images in the database....

Hope to get solutions as soon as possible...
Thanks...

raf
04-06-2003, 09:33 AM
Use one thread per problem.

About the select. If you are concatination (= linking straighthtml and variablevalues, you need to end the html parts with double quotes.

Like this
"SELECT * FROM product WHERE Cat='" & Food & "'"

I don't know the rest of your code, since i always use DSN less connections. It's faster + if your going to host your site on another server, you probably will have to pay to create the DSN



About the images. There have been some threads about that her. Just run a search for "databases images" or something like that.

It comes down to:
- save the filename (or part of the filenames addres, say starting from the virtual root)
- select the filenam (in your asp-pages) and insert it as a codesippet into the html that you generate.
like

<img height="55" width="180" src="<%= recordset.Fields("filename")%>" border="0">

Mhtml
04-07-2003, 08:15 AM
Try www.stardeveloper.com .. :)

helLO
04-07-2003, 10:56 AM
Thanks...
I tried using with double quotes, but to no avail...
Record.Open "SELECT * FROM product WHERE Cat='"&Food&"'",Connect

The full coding are:

<%@ language = "VBScript"%>

<html>
<head><title>Foods</title></head>
<body>

<%
'Declare variables
Dim Connect
Dim Record
'Create objects
Set Connect = Server.CreateObject("ADODB.Connection")
Set Record = Server.CreateObject("ADODB.Recordset")
'Open connection and run query
Connect.Open "Cart"
Record.Open "SELECT * FROM product WHERE Cat='"&Food&"'",Connect
%>


<table width=100% cellpadding=0 cellspacing=0 border=0 bgcolor=aqua>
<tr><td align=center><a href="health.asp">Health Care</a></td>
<td align=center><a href="groom.asp">Grooming</a></td>
<td align=center><a href="Misc.asp">Miscellaneous</a></td>
</tr>
</table>

<p><p>

<table border=1 align=center>
<tr><th>Cat</th>
<th>Description</th>
<th>Price($)</th>
</tr>

<%While Not Record.EOF%>

<tr align=center>
<td><%Response.Write(Record("Cat")&"")%></td>
<td><%Response.Write(Record("Description")&"")%></td>
<td><%Response.Write(Record("Price") & "<br>")%></td>
<%Record.MoveNext%>

<%Wend%>
</table>

<%Record.Close
Connect.Close
Set Record=Nothing
Set Connect=Nothing
%>

</body>
</html>

The above coding didn't work...

miranda
04-07-2003, 04:10 PM
"SELECT * FROM product WHERE Cat='" & Food & "'"
This will only return a result if the datafield has the varable value of food as the value.
If you want to search for the word food and it is the only word in the datafield, do that like this
"SELECT * FROM product WHERE Cat='Food'"

USE <%OPTION EXPLICIT%> at the top of your pages and you would have found that you were using Food as a variable

helLO
04-08-2003, 03:40 AM
Thanks... It works...

So u mean that this: <%OPTION EXPLICIT%> will state the "food" as a variable?

By the way, I still dun get how to get image from database and how to store image into the database? How to set the image in the database?

miranda
04-08-2003, 04:37 AM
A big negative about VBscript and Visual Basic versions prior to VB.Net is that it lets you implicitly declare variables. In other words you don't have to declare them at all before you use them. The problem without using option explicit is you may have a variable called IntTemperature and assign a value to it, and then later on try to use it as IntTemperture. Because the variable is not explicitly declared the 2nd one is actually a new variable with a new value. By using option explicit you have forced variabe declaration before they can be used. When it comes to debugging your code this proves to be invaluable.

How do you want to store the image? 1) as a blob (binary object code) or 2) as a url string? option 2 is much easier to do.

helLO
04-08-2003, 01:51 PM
:thumbsup: Thanks...


What is the difference between explicitly declared and those normal declarations(e.g. dim ABC)?


I think the 2nd 1 should be much better... But how to store it into the database and get it from the database?

Mhtml
04-08-2003, 03:43 PM
OPTION EXPLICIT means that you have to dimension all variables before you use them.

miranda
04-08-2003, 06:16 PM
to get the name of the image into the database, just include a text field for the image into a form, and just process it like any other form field. all you need to do then is upload the image into your images directory. then to display on the page just do it like so

<img src="/images/<%=rs("images")%>.gif">


you are explicitly declaring the variable when you use Dim
you are implicitly declaring a variable if you dont dim it first. VB does not require you to dim the variable. by using
<%option explicit%> at the top of the page you are forcing declaration which will show you any typographical errors in your code. It will save you countless hours debugging your program when used.

helLO
04-09-2003, 03:58 AM
Thanks for the explainations... i understood...

how do i do the pathing in the database?
The word "images" is it the table name of the images?
How would the SQL statement be? Example?

Sorry, i'm pretty lost and new abt this...

:confused:

miranda
04-09-2003, 04:16 AM
on the page that has the form on it just add a text field like so
<input type="text" name="image">

then just include that as a form element on the page that handles the form input into the database.

All that is left is to ftp the image into the proper directory or to upload the image to that directory. It is as simple as that

helLO
04-11-2003, 03:44 PM
But this method is to get image from the database, right? But how can i store image thru a website into the database?

miranda
04-11-2003, 09:15 PM
No, it is storing it into the database!

I suggest you read up on how to insert a record into a database.

Here are some sites for beginners to learn basic asp programming skills.

http://msdn.microsoft.com/howto/webdev.asp

http://www.w3schools.com/asp/asp_intro.asp

http://www.activeserverpages.com/tutorials/

http://www.learnasp.com/learn/newbie.asp

helLO
05-13-2003, 11:01 AM
Thanks...
:)