Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: ph_getwebparm example Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
phil13
Groupie
Groupie
Avatar

Joined: December 19 2004
Location: France
Online Status: Offline
Posts: 60
Posted: December 28 2004 at 11:59 | IP Logged Quote phil13

Hi,

after have spent many hours trying to use ph_getwebparm i found the good syntax.

Here is the code for someone interrested :

You first create ESSAI as global variable in powerhome.

You copy the following code in a file and save it as "example.psp" in the powerhome web directory.

in a browser, you call localhost/example.psp

You enter a value, hello for example and click on the button. And hello go in the ESSAI field.

<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Nouvelle page 1</title>
<script language="JavaScript">

function updatePHfield(PHfield, webfield)
{document.execsendkeys.sendkeys.value = "ph_setglobal_s ( '" + PHfield + "', ph_getwebparm('" + webfield + "') )" ;document.execsendkeys.submit(); }

</script>

</head>

<body bgcolor="#C0C0C0">


<form method="post" name="execsendkeys" action="/ph-cgi/execsendkeys">
<input type="hidden" name="sendkeys" value="">
<input type="hidden" name="nexturl" value="/essai2.psp">
<p align="center"><font size="6"><b>ph_getwebparm test</b></font></p>

<input type="text" name="AAA" size="20">
<input name="a1on" type="button" value="write in Powerhome 'ESSA'I global variable" onclick="updatePHfield('ESSAI', 'AAA')" style="color: #008000" name="a1on">
<p>

</form>

</body>

</html>
Back to Top View phil13's Profile Search for other posts by phil13
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 28 2004 at 23:28 | IP Logged Quote dhoward

Philippe,

I cant remember if you had asked me concerning PSP samples or not and if so, Im sorry I havent had a chance to get some together.

I tested out your code and it indeed works, though I havent taken the time to trace the code to find out why . However, it was not the intended method of use for the ph_getwebparm function. Ive pasted a couple of simple examples that go together below showing PSP programming and the intended use of the ph_getwebparm function.

The main PSP page is pasted below. In my sample, Ive named it "macrolist.psp" and placed it in the web directory. It dynamically builds a dropdown list box of available macros to play within PowerHome.

<html>
<head>
<title>PowerHome Macro List</title>
</head>
<body bgcolor="#ffffff">
<form method="get" action="playmacro.psp">Macro: <select name="id" size=1>
<option value="">
<% ph_rtne(ph_sqlselect(1,"select id from macroheader order by 1") + ph_setvar_a(1,1,1) + ph_doloop("ph_concatvar(1,2,'<option value=~~"' + ph_getdata(1,ph_getvar_n(1,1),1) + '~~">' + ph_getdata(1,ph_getvar_n(1,1),1) + '~r~n') + ph_rtne(ph_addtovar(1,1,1))","ph_getvar_n(1,1) <= ph_getsqlrows(1)")) + ph_getvar_s(1,2) + ph_rtne(ph_sqldestroy(1)) %>
</select>
<input type="submit" value="Play">
</form>
</body>
</html>

When you press on the "play" button, the "playmacro.psp" file will be called. This file uses the ph_getwebparm function to retrieve the value of the passed macro ID, plays it, and then redirects the page to the "macrolist.psp" file. The source is below:

<% ph_rtne(ph_macro(ph_getwebparm("id"))) %>
<html><head><title>PowerHome Redirect</title><script>location.replace("macrolist.psp")</script></head></html>

Hope this sheds a little light on PSP pages for anyone whose interested.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 28 2004 at 23:45 | IP Logged Quote TonyNo

Thanks, Dave. I was one person that asked about that.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 29 2004 at 00:35 | IP Logged Quote dhoward

Oops, Sorry Tony .

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 29 2004 at 01:04 | IP Logged Quote TonyNo

I don't doubt that Phil asked, too.

It seems that using the sql stuff can really make PH shine.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
phil13
Groupie
Groupie
Avatar

Joined: December 19 2004
Location: France
Online Status: Offline
Posts: 60
Posted: December 29 2004 at 04:36 | IP Logged Quote phil13

ouaha !

Even if i don't really understand your formula ... i find impressive the power of using sql in powerhome.

I think i have to learn SQL if i want make something really interesting.

Also, if you have others little piece of SQL code ...

Back to Top View phil13's Profile Search for other posts by phil13
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 30 2004 at 23:18 | IP Logged Quote dhoward

Well, dont have any specific pieces so will give a many SQL primer.

First off, PowerHome uses the Sybase Adaptive Server Anywhere Relational SQL database engine. A big name for pretty much just a structured file. This file is pwrhome.db in the database directory of PowerHome and is simply referred to as the database. Part of the engine is a separate executable that is our interface to the database. This executable handles retrieving, inserting, and updating of data within the database. The way we communicate with the engine is with a standardized language called SQL (Structured Query Language). Even though SQL is a standard, of course everyone who implements it adds their own flavor.

Before we delve into SQL, lets talk a little about a database. A database is a repository for data. It mainly consists of tables with each of these tables containing rows and columns. Each table will usually contain related data with this data being broken down into columns. A simple example would be a table containing data about an employee. You would want to know the employee's first and last name, employee number, hire date, salary, etc. Each of these related pieces of information would be contained within individual columns. The information for a single employee would be a record or a row within the table. If you had 10 employees, you would have 10 rows. While the structure of a table (the columns) is more or less fixed (it can be changed while designing), you can insert, delete, or update rows at will (you've hired employees, fired employees, or gave them a raise ;-)

Each column of data, will be of a specific type, usually character (such as their name), numeric (such as salary and employee number), or a date (such as the hire date). The data you place within a column must match the datatype of the column.

In addition to tables containing data within a database, you will usually have indexes and primary keys on your tables. An index will speed searching and retrieving of data from the database. A primary key (unique) creates an index on the table as well as ensures that no duplicate records can be created. When you create an index or a primary key, you identify what columns make up the key or index. In the case of the primary key, the column or combination of columns must contain unique information from one row to the next.

Databases can also contain their own code and "rules". When you update a row in one table, you could have a "trigger" that automatically updates a row in another table.

The last piece of background to introduce is table relationship. Usually tables are related to one another. Often this relationship is a "parent-child" relationship. In PowerHome, we can see this in the MACROHEADER and MACRODETAIL tables. The MACROHEADER table contains the ID and DESCRIPTION of a macro as well as whether it should appear in the macro dropdown listbox, etc.   The MACROHEADER table contains one and only one row for each macro (the ID is unique and is the primary key). The MACRODETAIL table contains the individual lines that make up the macro. If your macro has 10 lines of code, then the MACRODETAIL table will have 10 rows for that macro. This is also called a "one to many" relationship.

Now thats out of the way, lets talk a little about SQL. The structure of the PowerHome database is detailed in one of the appendices of the PowerHome Users Guide. It lists each table and the columns and datatypes that make up the tables. There are a number of SQL commands but the most commonly used during database access are INSERT, UPDATE, DELETE, and SELECT. They are pretty much self-explanatory. The INSERT statement will insert new rows into the database and the DELETE statement will remove existing rows. The UPDATE statement will modify data within the database and the SELECT statement will retrieve data from the database.

We'll concentrate on the SELECT statement here. The general structure of the SELECT statement is:

SELECT column1,column2,columnxx FROM table1,table2,tablexx WHERE condition1 = xx

You must start each SELECT statement with the word SELECT. You will then have a comma separated list of column names containing the data you wish to select. You must follow this with the FROM keyword and then follow that with a comma separated list of table names containing the columns you are selecting data from. The WHERE clause is optional and allows you to limit the data by applying conditions.

Now, how is this immediately useful? Where, since the betas have been released, the manual has not been updated with the latest database changes. Under the "Reports" menu of PowerHome is the "SQL Query" report. Choosing this opens a window where you can type a freeform SQL statement to query the PowerHome database. As long as we know the name of a table, we can see it's columns as well as all of its rows by entering in the following SQL statement:

select * from tablename

The asterisk is a wildcard character and means to retrieve all columns from the specified table. To get a list of all the rows and columns of the MACROHEADER table, we could type:

select * from macroheader

Once we see the structure, we could then modify the SQL so that we get a list of all the rows and show just the ID and DESCRIPTION columns by typing:

select id,description from macroheader

If we wanted to play with the WHERE clause, we could say give me just the macros whose ID starts with A by typing:

select id,description from macroheader where id like 'A%'

A little explanation is due. The % (percent sign) in the where clause is a wildcard. The ID columns is a character datatype and in SQL, character types are always delimited by single quotes. If you are using wildcard characters in the where clause, then the required relational operator is "like". If we wanted to retrieve just the macros whose ID were "A", then we would type:

select id,description from macroheader where id = 'A'

We don't have a wildcard, so we use the "=" relational operator. If we actually have a macro with an ID of "A", then our SQL would return a single row (the primary key of MACROHEADER is ID and no more than one macro can ever have an ID of "A"). If we didnt have a macro with an ID of "A", then no rows would be returned.

To finish up this intro, let also talk about an additional clause for the SELECT statement that allows us to sort the retrieved data. It is the ORDER BY clause and appears after the WHERE clause. If we wanted our data sorted by the ID column, then we would type:

select id,description from macroheader order by id

I'll conclude this into with a link to an online reference for Adaptive Server Anywhere:

http://sybooks.sybase.com/onlinebooks/group-sas/awg0700e/dbrfen7

HTH,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: April 04 2005 at 08:35 | IP Logged Quote TonyNo

Finally getting around to digesting this.

It looks like this portion of playmacro.psp...

Code:
location.replace("macrolist.psp")


Should be like this...

Code:
location.replace("/macrolist.psp")


Tony
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 05 2005 at 17:19 | IP Logged Quote TonyNo

Back to the topic...

I'm trying to use ph_getwebparm here:

<% ph_irdesc( ph_getwebparm ( "dev" ), ph_getwebparm ( "key" ) ) %>

<table border="0" width="221" cellspacing="0" cellpadding="0">
<tr>
    <td width="49"><a href="?dev=DIRECTIVO&key=EXIT"><img src="/images/pdadtv_0.bmp" width="49" height="45" border="0" alt="exit"></a></td>

Am I not doing this correctly? Do I need to assign the parameter to a local?
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 05 2005 at 20:48 | IP Logged Quote TonyNo

Nevermind, I got it!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 06 2005 at 16:34 | IP Logged Quote dhoward

Tony,

What was it? The syntax looked correct.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 06 2005 at 18:59 | IP Logged Quote TonyNo

I was calling an IR command that I didn't learn yet.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 10 2005 at 15:46 | IP Logged Quote dhoward

Dohh!!
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 21 2005 at 21:08 | IP Logged Quote TonyNo

Is there a way to tweak this...

Code:
<% ph_rtne(ph_sqlselect(1,"select id from macroheader order by 1") + ph_setvar_a(1,1,1) + ph_doloop("ph_concatvar(1,2,'<option value=~~"' + ph_getdata(1,ph_getvar_n(1,1),1) + '~~">' + ph_getdata(1,ph_getvar_n(1,1),1) + '~r~n') + ph_rtne(ph_addtovar(1,1,1))","ph_getvar_n(1,1) <= ph_getsqlrows(1)")) + ph_getvar_s(1,2) + ph_rtne(ph_sqldestroy(1)) %>


...to list out something like Global variables?

Edited by TonyNo
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: July 18 2005 at 16:27 | IP Logged Quote dhoward

Tony,

Below is the above code (tweaked a little bit using the latest functions) set to retrieve the ID's of the global variables.

Code:
<%ph_rtne(ph_sqlselect(1,"select id from global_variables order by 1"))%>
<%ph_rtne(ph_forloopwinc("ph_concatvar(1,2,ph_getdata(1,p h_getvar_n(1,1),1) + '<br>~r~n')",1,[SQLROWS1],1,1) + ph_sqldestroy(1))%>
<%ph_getvar_s(1,2)%>


Also take a look at the below code. It uses PSP to call a vbscript to simplify the looping code. Kind of a quasi-ASP way to do it.

The first is the PSP file:

Code:
<%ph_rtne(ph_runscript_0(ph_getphwebdir() +

"\ttgv.vbs","vbscript",0,0,"main"))%>
<html>
<body>
<table>
<%ph_getvar_s(1,2)%>
</table>
</body>
</html>



The second is the vbs code in a file (located in the PowerHome web directory but could be really anywhere) named "ttgv.vbs"

Code:

sub main()
     dim i_row,i_rows
     dim s_html

     ph.sqlselect 1,"select id,value from global_variables order by 1"
     i_rows = ph.getsqlrows(1)

     for i_row = 1 to i_rows
           s_html = s_html + "<tr><td>" + ph.getdata(1,cint(i_row),1) + "</td><td>" + ph.getdata(1,cint(i_row),2) + "</td></tr>" + vbcrlf
     next

     ph.sqldestroy(1)

     ph.setvar_s 1,2,s_html
end sub



Hope this opens up new avenues for you to explore.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: July 18 2005 at 17:34 | IP Logged Quote TonyNo

Sweet! Digestion of code commmencing in 01:24:00!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: July 18 2005 at 20:53 | IP Logged Quote TonyNo

Uhm, the first code block does not work and the script version crashed PH.

Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: July 19 2005 at 10:08 | IP Logged Quote dhoward

Tony,

I checked out the code and think Ive found the problem with the first PSP script. If you look at the copy and paste below:

ph_getdata(1,p h_getvar_n(1,1),1)

You can see a space between p and h in the ph_getvar_n. Don't know why this editor goofs up code copies and paste but this is probably the problem.

I also looked at the vbscript code and could not find a problem. If you copy and paste just the vbscript into the script editor and do a "Check Script", do you get back any errors? What happens when you run it? When you say crashes PowerHome, does it give you any kind of error message?

Let me know and we'll get it worked out.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: July 19 2005 at 20:15 | IP Logged Quote TonyNo

Good catch, Dave!

Here is the result of me playing with the first PSP bit. It creates a table to display the global name and its value. I just noticed that the psp/vbs bit does the same thing!

Code:
<html>
<body>
<table>
<% ph_rtne( ph_sqlselect( 1, "select id, value from global_variables order by 1")) %>
<% ph_rtne( ph_forloopwinc( "ph_concatvar( 1, 2, '<tr><td>' + ph_getdata( 1, ph_getvar_n( 1, 1),1) + '</td><td>' + ph_getdata( 1, ph_getvar_n( 1, 1), 2) + '</td></tr>~r~n')", 1, [SQLROWS1], 1, 1) + ph_sqldestroy( 1)) %>
<% ph_getvar_s(1, 2)%>
</table>
</body>
</html>


Now the psp/vbs works! Maybe that "p h_" set up a bad situation?
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 

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