Calorie Counter Using WAP and ASP - Application Deconstruction: Search.asp
(Page 4 of 4 )
This file contains the DSN-less connection, a SQL query, and the results. Note that the SQL query uses a like clause. This allows you to enter part of a food name and get back every food that contains that search string. This feature is useful for any type of SQL query where the exact search string is vague.
<%@ Language = "JScript"; %><% Response.ContentType = "text/vnd.wap.wml";
%><?xml version="1.0"?>
<!-- #include file="adojavas.inc" -->
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml_1.2.xml">
<wml>
<card id="card1" title="Food Results">
<p>
Food Search Results<br/>
<%
// dsn-less connection to food.mdb
conn = Server.CreateObject("ADODB.Connection");
rs = Server.CreateObject("ADODB.Recordset");
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" +
Server.MapPath("Food.mdb") + ";");
// create a string to hold the SQL query
sqlQuery = "SELECT * FROM tblFoods where Description like '%" + Request.QueryString("Food") + "%' ORDER BY DESCRIPTION";
// execute the query on the database
rs.Open(sqlQuery, conn, adOpenForwardOnly, adLockReadOnly, adCmdText);
while (!rs.EOF)
{
Response.Write("Description: ");
Response.Write(rs("Description") + "<br/>");
Response.Write("Serving: ");
Response.Write(rs("Unit") + "<br/>");
Response.Write("Fat: ");
Response.Write(rs("Fat") + "<br/>");
Response.Write("Calories: ");
Response.Write(rs("Calories") + "<br/>");
Response.Write("Carbs: ");
Response.Write(rs("Carb") + "<br/>");
Response.Write("Cholesterol: ");
Response.Write(rs("Cholesterol") + "<br/>");
Response.Write("-----------------");
Response.Write("<br/>");
rs.MoveNext();
}
conn.Close();
%>
</p>
</card>
</wml>
After these files are uploaded to the hosting server, you should be able to view them with any WAP enabled device, emulator, or browser. Now, you can’t use the “well, I didn’t know that the hamburger had 700 calories” excuse. Have fun, and stay healthy!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |