4 Replies Latest reply on Jul 11, 2006 3:49 PM by Newsgroup_User

    Display HTML table from property list

    dbohea
      Hello again folks.

      I'm trying to display a basic property list as an HTML table in a text member.

      Here's an example of my property list (it's basic username & password stuff):

      gDatabase = [#bwillis: "bruce", #vdiesel: "vin", #bpitt: "brad", #wallen: "woody"]

      I've found some examples of how to do this kind of thing but I'm not quite getting it right. Below is an example of what I'm attempting to use. I've put "???" in where I think I'm having trouble.

      global gDatabase

      -- display a list of all the records using HTML
      on browseDatabase

      -- HTML header
      htext = "<HTML><BODY BGCOLOR=#FFFFFF>"&RETURN

      -- put the table headings
      put "<TABLE><TR><TH>No.</TH><TH>Username</TH><TH>Password</TH></TR>"\
      &RETURN after htext

      -- loop through database and create table rows
      repeat with i = 1 to gDatabase.count
      put "<TR>" after htext
      put "<TD>"&i&"</TD>" after htext

      -- here's where I'm not sure...
      put "<TD>"???"</TD>" after htext

      put "</TR>"&RETURN after htext
      end repeat

      -- close out table and HTML
      put "</TABLE></BODY></HTML>" after htext

      -- place HTML in text member
      member("Database List").html = htext

      end

      I know you guys probably think I'm always on the blag for Lingo help but trust me, I do try very hard before resorting to forums for help.

      May all your geese be swans,

      Dan.
        • 1. Re: Display HTML table from property list
          Level 7
          Try this

          -- here's where I'm not sure...

          put "<TD>" & gDatabase.getPropAt(i) & "</TD>" after htext

          put "<TD>" & gDatabase[gDatabase.getPropAt(i)] & "</TD>" after htext


          • 2. Re: Display HTML table from property list
            Level 7
            By the way, as long as you will never need to store any other data about
            users (other than their password) your design will be fine. If there is any
            chance that you will want to add something later you may want to go ahead
            and prepare for that now, so that you won't have to as much modification
            later.

            So for example, suppose you wanted to assign eahc user to a specific group
            (like guest, superuser,admin, etc) and also wanted to track when any user
            info was updated.

            gDatabase = [#bwillis: [#password:"bruce", #permissions:"administrator",
            #lastmodified:"05/08/2006"] ]



            • 3. Re: Display HTML table from property list
              dbohea Level 1
              Thanks Dave. That works a treat.

              I'm still not too sure about how the second line in your solution works. Is that line retrieving and displaying the value (password)? If so, how?

              I understand your point in your second post - hence my recent posts about nested lists.

              The amount of beers I owe you for your help is steadily climbing.

              Thanks again Dave.
              • 4. Re: Display HTML table from property list
                Level 7
                If the list looks like this gDatabase = [#bwillis: "bruce", #vdiesel:
                "vin", #bpitt: "brad", #wallen:
                "woody"] then in the repeat loop when i = 1 the expression
                gDatabase.getPropAt(i) returns #bwillis" (a symbol). When you append a
                symbol to a string Director you get a string (I assume this is by design and
                not a fluke). In this case you are appending the <TD> tags, so it works. As
                good practice, you may want to use the string function to force Director to
                treat objects as a string when so desired.

                The next line uses the same expression, but because it is not being appended
                to a string (in the order things get executed), it remains a symbol.

                gDatabase[gDatabase.getPropAt(i)] > gDatabase[#bwillis] > "bruce"

                It is after this that it gets appended to the <TD> tags. So with each pass
                of the loop, you get the associated password.

                If you decide you will need to define multiple properties, you can adjust
                the code to match.

                gDatabase[#bwillis:[#password:"bruce"]]

                put "<TD>" & gDatabase.getPropAt(i).password] & "</TD>" after htext

                put "<TD>" & gDatabase[gDatabase.getPropAt(i).password] & "</TD>" after
                htext

                Now you can add as many properties to the user as your program needs.

                I have only had the pleasure of sampling the Americanized version of beer,
                my favorite being Guinness.