Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Need web programming help Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
judetf
Senior Member
Senior Member


Joined: January 23 2008
Online Status: Offline
Posts: 234
Posted: October 26 2008 at 08:23 | IP Logged Quote judetf

I can program in SQL decently, and I can program in html decently, but I am stuck trying to solve for something using PH to create a simple Insteon-related webpage. Any help appreciated.

In brief: I'd like to create a simple one-row, two column table with a dynamic list of all of my 'on' Insteon devices listed in the first cell and all of the 'off' devices in the second, with both cells valign'd to the top of their cells. (The code below includes an extra 'header' row for 'on/off' labels.)

I have the SQL to pull the list of Insteon devices, and I I can loop through the list and check whether each device is on or off.

But the best I have come up with so far is to go through them one device at a time and insert "</td><td>" in front of any device that is off and while that works, it results in multiple rows being created and so it's not one cell per column with the results flush to the top of the cell.

I'm sure there must be a way to determine on/off status for all devices up front and then return the results grouped according to status, which would make it easy, but that's where I'm stuck on my PH/web-programming knowledge.

Here's the code I've worked out so far, but I'm open to a complete revision if there is a smarter way to do this. Thanks.

<table border=1>
     <tr>
             <td>On</td>
             <td>Off</td>
     </tr>
     <tr>
<%
     ph_rtne(
     ph_sqlselect(1, "select id from insteondevices where typeid not in (1,39) order by id") +
     ph_setvar_a(1,1,1) +
     ph_setvar_s(1,2,"") +
     ph_forloop(
             "ph_concatvar(1,2,
                  '

     ' + if(ph_getinsteonstat(ph_getdata(1,ph_getvar_n(1,1),1))=1, '<td></td><td>', '<td>') + '

     ' + wordcap(ph_getdata(1,ph_getvar_n(1,1),1)) + '

             </td>
     </tr>'
             ) +

     ph_rtne(ph_addtovar(1,1,1))",
     1,
     ph_getsqlrows(1),
     1
     )
     ) +
     ph_getvar_s(1,2) +
     ph_rtne(ph_sqldestroy(1))
%>

</table>


Edited by judetf - October 26 2008 at 08:25
Back to Top View judetf's Profile Search for other posts by judetf
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: October 26 2008 at 12:13 | IP Logged Quote dhoward

judetf,

This should do it for you...
Code:

<html>
<body>
<table border=1>
     <tr>
        <td>On</td>
        <td>Off</td>
     </tr>
     <tr>
        <td valign=top><%ph_sql(0,"select id || '<br>' from insteondevices where status > 0 and typeid not in (1,39) order by id")%></td>
        <td valign=top><%ph_sql(0,"select id || '<br>' from insteondevices where status = 0 and typeid not in (1,39) order by id")%></td>
     </tr>
</table>
</body>
</html>


Hope this helps,

Dave.


Edited by dhoward - October 26 2008 at 12:19
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
judetf
Senior Member
Senior Member


Joined: January 23 2008
Online Status: Offline
Posts: 234
Posted: October 27 2008 at 06:22 | IP Logged Quote judetf

Dave,

Thanks. I had considered pulling the information from the insteondevices table but my brain told me that it must somehow be more accurate to use ph_getinsteonstat for each device...

Thanks for clearing it up!
jtf
Back to Top View judetf's Profile Search for other posts by judetf
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum