![]() |
![]() |
|
![]() |
Paradox Web Server Lesson 5 - Coding in Two Languages © 2001 Tony McGuire Lesson 5 - Coding in Two Languages This next part is where I struggled hardest. For some of you, this may be where you say "No Way". Once you "get" it, learn how helpful copy & paste is, and learn to use those Templates I keep mentioning it isn't bad at all. You just have to program in 2 languages at the same time: OPAL and HTML. This is also why I have become friends with HotMetal (www.softquad.com). It taught me to create HTML that is available to virtually any browser out there. Too many sites want to use the latest and greatest code possible; this is fine if you don't mind locking out the millions of AOL users and many Netscape users, as well as a large portion of the MAC community. While Microsoft says "So what, buy mine", I'm not ready to limit myself that much. OK. We worked out in #4 how to narrow a table to a set of records that need to be sent back to the user. Please understand that you _will not_ be sending the Paradox table to the user. You will be sending the data from the Paradox table in HTML format, and using HTML formatting codes/constructs to present the data to the end user (Internet Visitor). Let's start with the structure of your data, containing information about cars.
I probably left out some critical stuff, but I am not in the auto business. Let's just say that this is the information you gather from your clients selling cars, and then make available to people who want to buy stuff. Much of this stuff is specific to cars, but you could make this table generic (so it could handle many different types of items for sale) or you could have a different table for each type of item (the first would be easier to manage, the second would make your site faster due to smaller searches). I take the second route every time. Easier to manage, through coding, becomes less of an issue. You can make it manage itself. (For instance, a form on your site that retrieves new entries. The person entering the data selects the type of entry they are making; this dropdown becomes the "action" statement in your Internet form. This automatically causes Paradox to process this entry based on the type of entry it is based on the server.db entries and underlying library) Having applied the setrange() and setgenfilter() from Lesson #4, let's say that we have a table with 15 records (yours is a nationwide site, after all).You now need to send the record set to the user. The way I handle this is normally by starting with a fetchtemplate() retvar=fetchtemplate("carresultsheader")In the template table, the HTML field might look like this: <html> <head> <title>Cars that match your search criteria</title> </head> <body> What this does is retrieve the above HTML into the "retvar" variable. <html> tells the user's browser that the data they are receiving is HTML. The text between the <title></title> will appear in the user's browser as the title of the page they are viewing (top left of the browser, on the "blue" app title bar). Since this is a template designed specifically for setting up the return results from a search for a car, you could incorporate even more HTML into the template since every result would start the same way: <table width="100%"> <tr> <td>Model</td> <td>Price</td> <td>Year Built</td> <td>Mileage</td> <td>Color</td> <td>Owner</td> <td>Phone</td> <td>E-Mail</td> </tr> ; note that we do _not_ close the <table> construct I placed each of these opening/closing constructs on their own line only to make it a little easier to read. The <table> statement declares an HTML table for holding rows & columns of information (think of it as a spreadsheet). <tr> declares a row within the table. <td> declares the start of a column (cell). </td> closes the cell. </tr> ends the row. What this accomplishes is a "header" row for the data below it. Now, we need to get the data from the table and put it into matching rows (a record) and columns/cells (each field of data). tc.open("autosforsale.db",databasevar,"carprice") tc.setrange(cr,lp,hp) scan tc : retvar=retvar+"<tr>" retvar=retvar+"<td>"+tc.model+"</td>" retvar=retvar+"<td>"+format("e$c",tc.price)+"</td>" retvar=retvar+"<td>"+strval(longint(tc.yb)+"</td>" retvar=retvar+"<td>"+strval(tc.mileage)+"</td>" retvar=retvar+"<td>"+tc.color+"</td>" retvar=retvar+"<td>"+format("cc",tc.owner)+"</td>" retvar=retvar+"<td>"+tc.phone+"</td>" retvar=retvar+"<td><a href=\"mailto:"+tc.email+"\">"+tc.email+"</td>" retvar=retvar+"</tr>" endscan tc.close()The scan, of course, steps through each record of the limited view table, and applies the code between scan....endscan retvar=retvar+".." results in the individual lines being added to the string variable retvar. This is very handy. You might be tempted to make one long line out of this. But remember that a string variable is very limited in size as to each decalaration; by breaking the lines down, you are only limited by the total character count of the string variable. The end result of this is that each field of the table is placed in a column that matches the header you got from the fetchtemplate() command. By starting the return from each record with "<tr>" you are creating a new row, just as in the Paradox table. Using "</tr>" declares the end of the row, thus matching each row in the Internet table with a record in your Paradox table. When you close the tcursor, the next thing you will likely do is declare the end of the Internet table. You do this with: retvar=retvar+"</table>" Now, you have the information your user asked for, formatted for a browser, that the user can make some sense of. It is nicely formatted in rows and columns. Next, you need to declare that you have reached the end. You can always add as much as you want by adding retvar=retvar+".....", but we'll call this the end of our return page. You could use another fetchtemplate() command to get the last bit, but there is so little that I usually include the ending code in the method I am using to get the data and return the results: retvar=retvar+"</body>" ; close the body of the HTML page retvar=retvar+"</html>" ; let the browser know that this is then end response.resultstring=retvar return true endmethodThat is the whole thing! We just got the user's search criteria (lesson #4), did a "search" against a Paradox table, and returned the results back to the person on the Internet who made the request. NOTE: I did not open a textstream and create an HTML file. The return data gets sent directly back to the user's browser. There are no files to maintain. The hard drive gets accessed in order to retrieve the data, but not to create a file, nor for the user's browser to read from. This isn't desirable in every case; you may want a "permanent" for future reference. If this is the case, then you can always open a textstream (naming it based on whatever schema you want), then use something like: textstreamvar.writeline(retvar) textstreamvar.commit() textstreamvar.close() response.resultfile=file_name_you_opened_the_textstream_with return true endmethodIf you want the underlying data you send to the user to appear nice (in case they look at the source code), add \n wherever you want a line break (new line) in your HTML code (I usually do this at the end of each record; thus "</tr>" becomes </tr>\n ). Oh! Forgot to explain the "mailto:" stuff. What this does is not only display the content of the e-mail field, but makes it "clickable". The results is that the viewer can click on the e-mail on-screen and their e-mail client automatically pops up with the e-mail addressed to this owner (from the table's e-mail field). Also, the width="100%" makes the HTML table automatically size to the full width of the viewer's screen. It widens/shrinks the columns of data to fit the screen of the person viewing the data. There are individual commands that can be added to the <td> declarations that cause the cell to be aligned left/center/right, change font size/color/bold/etc. but you'll have to discover these. Q & A Discussion of this article |
![]() Feedback | Paradox Day | Who Uses Paradox | I Use Paradox | Downloads ![]() |
|
![]() The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation. Paradox is a registered trademark of Corel Corporation. ![]() |
|
![]() Modified: 15 May 2003 Terms of Use / Legal Disclaimer ![]() |
![]() Copyright © 2001- 2003 Paradox Community. All rights reserved. Company and product names are trademarks or registered trademarks of their respective companies. Authors hold the copyrights to their own works. Please contact the author of any article for details. ![]() |
![]() |
|