By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

QuickFom question

P: n/a

I am new to PHP. I am trying to create a QuickForm Select element and
load it from a database with 'HTML_QuickForm::LoadQuery'.

I figured it would be a lot easier than build all of that code by hand.
The only thing is I can not find much info on using these objects. I can
not read the manual for this as I can for Java API's. I am able to
display the Select object with label but no data.

Can some one point me in the right direction? I am missing something
stupid..

This is the code sniplet:

$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadQuery($conn, 'select id, name from catagory order by name',
'name', 'id');
$form->addElement($s);
$form->display();
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 9 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
IchBin schrieb:
>
I am new to PHP. I am trying to create a QuickForm Select element and
load it from a database with 'HTML_QuickForm::LoadQuery'.

I figured it would be a lot easier than build all of that code by hand.
The only thing is I can not find much info on using these objects. I can
not read the manual for this as I can for Java API's. I am able to
display the Select object with label but no data.

Can some one point me in the right direction? I am missing something
stupid..

This is the code sniplet:

$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadQuery($conn, 'select id, name from catagory order by name',
You are sure it is 'catagory', not 'category'?
^ ^

Markus
Aug 9 '06 #2

P: n/a
Markus Ernst wrote:
IchBin schrieb:
>>
I am new to PHP. I am trying to create a QuickForm Select element and
load it from a database with 'HTML_QuickForm::LoadQuery'.

I figured it would be a lot easier than build all of that code by
hand. The only thing is I can not find much info on using these
objects. I can not read the manual for this as I can for Java API's. I
am able to display the Select object with label but no data.

Can some one point me in the right direction? I am missing something
stupid..

This is the code sniplet:

$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadQuery($conn, 'select id, name from catagory order by name',

You are sure it is 'catagory', not 'category'?
^ ^

Markus
Nice catch but unfortunately my misspelling is consistent in the column
name. I wish their were examples across the internet so I can understand
this function. I have only found one reference to
'HTML_QuickForm::LoadQuery'. I guess I could try
'HTML_QuickForm::loadDbResult' but I am not using the DB abstraction
currently in my program.

Is there a place where the author answers questions about their PEAR
classes. Again I am new to PHP and I am a Java programmer learning PHP.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 9 '06 #3

P: n/a
IchBin wrote:
>
I am new to PHP. I am trying to create a QuickForm Select element and
load it from a database with 'HTML_QuickForm::LoadQuery'.

I figured it would be a lot easier than build all of that code by hand.
The only thing is I can not find much info on using these objects. I can
not read the manual for this as I can for Java API's. I am able to
display the Select object with label but no data.

Can some one point me in the right direction? I am missing something
stupid..

This is the code sniplet:

$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadQuery($conn, 'select id, name from catagory order by name',
'name', 'id');
$form->addElement($s);
$form->display();
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
For some reason I can get the 'HTML_QuickForm::loadDbResult' to work but
not the 'HTML_QuickForm::loadQuery'. I rather use the loadQuery because
it takes less code on my part. Beats me!

//
// This works for HTML_QuickForm::loadDbResult()
$db =& DB::connect($dsn, $options);
if (PEAR::isError($db)) {
die($db->getMessage());
}
$result =& $db->query($catagory_dropdown_select);

if (PEAR::isError($result)) {
die($res->getMessage());
}
$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadDbResult($result, 'name', 'id');
$form->addElement($s);
$form->display();

I love HSQLDB and use in my Java code. I guess I'll use MySQL for PHP. I
am not a big fan of MySQL but it easy to use and 95% of Hosting sites
seem to run it..

Problem example: I noticed that when I do an 'ORDER BY' on my 'SELECT'
statement this is the screwed-up ORDER that it comes back for 'Catagory':

ApacheTomcat
.Net
AJAX
Buddhist
C and C++
C Sharp
Cisco
CSS
DataBase
Design Patterns
Aug 9 '06 #4

P: n/a
IchBin wrote:
Markus Ernst wrote:
>IchBin schrieb:
>>>
I am new to PHP. I am trying to create a QuickForm Select element and
load it from a database with 'HTML_QuickForm::LoadQuery'.

I figured it would be a lot easier than build all of that code by
hand. The only thing is I can not find much info on using these
objects. I can not read the manual for this as I can for Java API's.
I am able to display the Select object with label but no data.

Can some one point me in the right direction? I am missing something
stupid..

This is the code sniplet:

$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadQuery($conn, 'select id, name from catagory order by name',

You are sure it is 'catagory', not 'category'?
^ ^

Markus

Nice catch but unfortunately my misspelling is consistent in the column
name. I wish their were examples across the internet so I can understand
this function. I have only found one reference to
'HTML_QuickForm::LoadQuery'. I guess I could try
'HTML_QuickForm::loadDbResult' but I am not using the DB abstraction
currently in my program.

Is there a place where the author answers questions about their PEAR
classes. Again I am new to PHP and I am a Java programmer learning PHP.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
For some reason I can get the 'HTML_QuickForm::loadDbResult' to work but
not the 'HTML_QuickForm::loadQuery'. I rather use the loadQuery because
it takes less code on my part. Beats me!

//
// This works for HTML_QuickForm::loadDbResult()
$db =& DB::connect($dsn, $options);
if (PEAR::isError($db)) {
die($db->getMessage());
}
$result =& $db->query($catagory_dropdown_select);

if (PEAR::isError($result)) {
die($res->getMessage());
}
$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadDbResult($result, 'name', 'id');
$form->addElement($s);
$form->display();

I love HSQLDB and use in my Java code. I guess I'll use MySQL for PHP. I
am not a big fan of MySQL but it easy to use and 95% of Hosting sites
seem to run it..

Problem example: I noticed that when I do an 'ORDER BY' on my 'SELECT'
statement this is the screwed-up ORDER that it comes back for 'Catagory':

ApacheTomcat
.Net
AJAX
Buddhist
C and C++
C Sharp
Cisco
CSS
DataBase
Design Patterns
Aug 9 '06 #5

P: n/a
IchBin wrote:
Markus Ernst wrote:
>IchBin schrieb:
>>>
I am new to PHP. I am trying to create a QuickForm Select element and
load it from a database with 'HTML_QuickForm::LoadQuery'.

I figured it would be a lot easier than build all of that code by
hand. The only thing is I can not find much info on using these
objects. I can not read the manual for this as I can for Java API's.
I am able to display the Select object with label but no data.

Can some one point me in the right direction? I am missing something
stupid..

This is the code sniplet:

$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadQuery($conn, 'select id, name from catagory order by name',

You are sure it is 'catagory', not 'category'?
^ ^

Markus

Nice catch but unfortunately my misspelling is consistent in the column
name. I wish their were examples across the internet so I can understand
this function. I have only found one reference to
'HTML_QuickForm::LoadQuery'. I guess I could try
'HTML_QuickForm::loadDbResult' but I am not using the DB abstraction
currently in my program.

Is there a place where the author answers questions about their PEAR
classes. Again I am new to PHP and I am a Java programmer learning PHP.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
For some reason I can get the 'HTML_QuickForm::loadDbResult' to work but
not the 'HTML_QuickForm::loadQuery'. I rather use the loadQuery because
it takes less code on my part. Beats me!

//
// This works for HTML_QuickForm::loadDbResult()
$db =& DB::connect($dsn, $options);
if (PEAR::isError($db)) {
die($db->getMessage());
}
$result =& $db->query($catagory_dropdown_select);

if (PEAR::isError($result)) {
die($res->getMessage());
}
$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadDbResult($result, 'name', 'id');
$form->addElement($s);
$form->display();

I love HSQLDB and use in my Java code. I guess I'll use MySQL for PHP. I
am not a big fan of MySQL but it easy to use and 95% of Hosting sites
seem to run it..

Problem example: I noticed that when I do an 'ORDER BY' on my 'SELECT'
statement this is the screwed-up ORDER that it comes back for 'Catagory':

ApacheTomcat
.Net
AJAX
Buddhist
C and C++
C Sharp
Cisco
CSS
DataBase
Design Patterns
Aug 9 '06 #6

P: n/a

"IchBin" <we******@ptd.netwrote in message
news:Uz********************@ptd.net...
>
I am new to PHP. I am trying to create a QuickForm Select element and load
it from a database with 'HTML_QuickForm::LoadQuery'.

I figured it would be a lot easier than build all of that code by hand.
The only thing is I can not find much info on using these objects. I can
not read the manual for this as I can for Java API's. I am able to display
the Select object with label but no data.

Can some one point me in the right direction? I am missing something
stupid..

This is the code sniplet:

$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadQuery($conn, 'select id, name from catagory order by name',
'name', 'id');
$form->addElement($s);
$form->display();
I don't know if this has **anything** to do with your problem, but could it
be that the data are in table "category", not "catagory"?

By the way, that is an interesting name - "I am" or "I have been".

Shelly
Aug 9 '06 #7

P: n/a
Shelly wrote:
"IchBin" <we******@ptd.netwrote in message
news:Uz********************@ptd.net...
>I am new to PHP. I am trying to create a QuickForm Select element and load
it from a database with 'HTML_QuickForm::LoadQuery'.

I figured it would be a lot easier than build all of that code by hand.
The only thing is I can not find much info on using these objects. I can
not read the manual for this as I can for Java API's. I am able to display
the Select object with label but no data.

Can some one point me in the right direction? I am missing something
stupid..

This is the code sniplet:

$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadQuery($conn, 'select id, name from catagory order by name',
'name', 'id');
$form->addElement($s);
$form->display();

I don't know if this has **anything** to do with your problem, but could it
be that the data are in table "category", not "catagory"?

By the way, that is an interesting name - "I am" or "I have been".

Shelly

Thanks for replying. That question was asked on the first reply to my
initial message. Since, I have gotten around the problem by using
'HTML_QuickForm::loadDbResult' instead of 'HTML_QuickForm::loadQuery'.
You can check the thread for info. Still wish that I could get
'HTML_QuickForm::loadQuery' to work.

Also wish that this class had better documentation and not just the specs.

Oh.. I prefer the current tense of my handle.... as a philosophical
starting point... lol

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 9 '06 #8

P: n/a
IchBin schrieb:
>>
Is there a place where the author answers questions about their PEAR
classes. Again I am new to PHP and I am a Java programmer learning PHP.

For some reason I can get the 'HTML_QuickForm::loadDbResult' to work but
not the 'HTML_QuickForm::loadQuery'. I rather use the loadQuery because
it takes less code on my part. Beats me!
Sorry I am not familiar with this part of QuickForm. Anyway, for the
case you have not found this yourself, there is actually an API
documentation:
http://pear.php.net/package/HTML_Qui...rm_select.html

You might get more specific informations via the PEAR general mailing
list, join it at
http://pear.php.net/support/lists.php

HTH
Markus
Aug 10 '06 #9

P: n/a
IchBin wrote:
>
I am new to PHP. I am trying to create a QuickForm Select element and
load it from a database with 'HTML_QuickForm::LoadQuery'.

I figured it would be a lot easier than build all of that code by hand.
The only thing is I can not find much info on using these objects. I can
not read the manual for this as I can for Java API's. I am able to
display the Select object with label but no data.

Can some one point me in the right direction? I am missing something
stupid..

This is the code sniplet:

$form = new HTML_QuickForm();
$s =& $form->createElement('select','name','Catagory:' );
$s->loadQuery($conn, 'select id, name from catagory order by name',
'name', 'id');
$form->addElement($s);
$form->display();
Well for what it's worth. I figured out why I could not get
'HTML_QuickForm::loadQuery' to work but able to get
'HTML_QuickForm::loadDbResult' working.

The api specs states for a 'loadDbResult' that I should use DB_result
object for the first parameter. So this was no problem because I did all
of the db work and passed the result.

The api specs states for a 'loadQuery' that I should user either
an existing DB connection or a valid dsn for the first parameter. Well I
got in to my head to use the $dsn var. Well I kept that var in another
php file 'config.php'. So come time to use it, even having an include
for that file, the running php script could not find it.

It seems that using a $dsn for 'loadQuery' requires that the $dsn be
defined in the script that references it. So once I saw this, I said
hell with that and just used the $db object. Which is nice because I was
not using the DB abstraction when I first tried using 'loadQuery'. I
added to work with 'loadDbResult'.

Conclusion for me is that when there are a lot of <Selectitems with
one or mores <Selectobjects on a form, this is perfect. Not sure what
the extra overhead is for this 'user friendly coding' is but can't be
much for this abstraction...

$s =& $form->createElement('select','name','Category:' );
$s->loadQuery($db, $category_dropdown_select);
$form->addElement($s);

Again, I am new to this php scripting lang stuff. Just trying to get my
feet wet!

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 10 '06 #10

P: n/a
IchBin schrieb:
The api specs states for a 'loadQuery' that I should user either
an existing DB connection or a valid dsn for the first parameter. Well I
got in to my head to use the $dsn var. Well I kept that var in another
php file 'config.php'. So come time to use it, even having an include
for that file, the running php script could not find it.
Just a guess - the missing $dsn variable could be a namespace issue.
Variables defined inside a function or a class will not be available in
the global namespace. For example, if you connect via a function like:

<?php
function &connect_db($host, $user, $pass) {
$dsn = array('host'=>$host, 'user'=>$user, 'pass'=>$pass);
include_once('DB.php');
$db =& DB::connect($dsn);
return $db;
}
$db =& connect_db('myhost', 'myuser', 'mypassword');
?>

$dsn is not set in the global namespace. Or the include happens inside a
function or class:

<?php
function &connect_db() {
include_once('config.php'); // contains the $dsn declaration
include_once('DB.php');
$db =& DB::connect($dsn);
return $db;
}
$db =& connect_db();
....
do_something($dsn); // I think that won't work
....
include('config.php');
do_something_else($dsn); // I think that won't work either
?>

I assume that also here the scope of $dsn is limited to connect_db(),
and include_once() prevents config.php from being included again.

--
Markus
Aug 11 '06 #11

P: n/a
Markus Ernst wrote:
IchBin schrieb:
>The api specs states for a 'loadQuery' that I should user either
an existing DB connection or a valid dsn for the first parameter. Well
I got in to my head to use the $dsn var. Well I kept that var in
another php file 'config.php'. So come time to use it, even having an
include for that file, the running php script could not find it.

Just a guess - the missing $dsn variable could be a namespace issue.
Variables defined inside a function or a class will not be available in
the global namespace. For example, if you connect via a function like:

<?php
function &connect_db($host, $user, $pass) {
$dsn = array('host'=>$host, 'user'=>$user, 'pass'=>$pass);
include_once('DB.php');
$db =& DB::connect($dsn);
return $db;
}
$db =& connect_db('myhost', 'myuser', 'mypassword');
?>

$dsn is not set in the global namespace. Or the include happens inside a
function or class:

<?php
function &connect_db() {
include_once('config.php'); // contains the $dsn declaration
include_once('DB.php');
$db =& DB::connect($dsn);
return $db;
}
$db =& connect_db();
...
do_something($dsn); // I think that won't work
...
include('config.php');
do_something_else($dsn); // I think that won't work either
?>

I assume that also here the scope of $dsn is limited to connect_db(),
and include_once() prevents config.php from being included again.
Markus, thank you so much for your analysis. It's funny because last
night I sat down and wanted to find out the scope of Classes, functions,
and vars with respect to their reference. I would like to continue to
code in an OOP\OOP fashion as I do in Java. Since I am running php 5 I
am trying to find out the difference to Java's OOD/OOP implementation.

For the $dsn problem. I have not codded in OOD just yet. So in the
config.php I have the following for $dsn:

$dsn = array(
'phptype' ='mysqli',
'username' ='usern',
'password' ='paswd',
'hostspec' ='localhost',
'port' ='3306',
'database' ='library',
);
$options = array(
'debug' =2,
'portability' =DB_PORTABILITY_ALL,
);

I am not explicitly defining $dsn in a class or function. It is just in
the config.php file. The calling php file is called 'openDB.php' and has
a include for the 'config.file'. This is my openDB.php:

//
require 'DB.php';
require 'HTML/QuickForm.php';
require 'php_errors.php';
//
// Configure the database connection
include 'sql_selects.php';
include 'config.php';

$db =& DB::connect($dsn, $options);
if (PEAR::isError($db)) {
die($db->getMessage());
}
//
// return the requested DB resultset
Function getQueryData($query){
//
// Proceed with catagory query...
$result =& $db->query($query);
//
// Always check that result is not an error
if (PEAR::isError($result)) {
die($res->getMessage());
}
return $result;
}

So in my main php file 'index.php' I would have the include for
'openDB.php' and eventually the reference to $dsn as in:

s->loadQuery($dsn, $category_dropdown_select);
where
s->loadQuery($db, $category_dropdown_select);
works and $dsn does not.
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 11 '06 #12

P: n/a
Markus Ernst wrote:
IchBin schrieb:
>The api specs states for a 'loadQuery' that I should user either
an existing DB connection or a valid dsn for the first parameter. Well
I got in to my head to use the $dsn var. Well I kept that var in
another php file 'config.php'. So come time to use it, even having an
include for that file, the running php script could not find it.

Just a guess - the missing $dsn variable could be a namespace issue.
Variables defined inside a function or a class will not be available in
the global namespace. For example, if you connect via a function like:

<?php
function &connect_db($host, $user, $pass) {
$dsn = array('host'=>$host, 'user'=>$user, 'pass'=>$pass);
include_once('DB.php');
$db =& DB::connect($dsn);
return $db;
}
$db =& connect_db('myhost', 'myuser', 'mypassword');
?>

$dsn is not set in the global namespace. Or the include happens inside a
function or class:

<?php
function &connect_db() {
include_once('config.php'); // contains the $dsn declaration
include_once('DB.php');
$db =& DB::connect($dsn);
return $db;
}
$db =& connect_db();
...
do_something($dsn); // I think that won't work
...
include('config.php');
do_something_else($dsn); // I think that won't work either
?>

I assume that also here the scope of $dsn is limited to connect_db(),
and include_once() prevents config.php from being included again.
Markus, thank you so much for your analysis. It's funny because last
night I sat down and wanted to find out the scope of Classes, functions,
and vars with respect to their reference. I would like to continue to
code in an OOD\OOP fashion as I do in Java. Since I am running php 5 I
am trying to find out the difference to Java's OOD/OOP implementation.

For the $dsn problem. I have not codded in OOD just yet. So in the
config.php I have the following for $dsn:

$dsn = array(
'phptype' ='mysqli',
'username' ='usern',
'password' ='paswd',
'hostspec' ='localhost',
'port' ='3306',
'database' ='library',
);
$options = array(
'debug' =2,
'portability' =DB_PORTABILITY_ALL,
);

I am not explicitly defining $dsn in a class or function. It is just in
the config.php file. The calling php file is called 'openDB.php' and has
a include for the 'config.file'. This is my openDB.php:

//
require 'DB.php';
require 'HTML/QuickForm.php';
require 'php_errors.php';
//
// Configure the database connection
include 'sql_selects.php';
include 'config.php';

$db =& DB::connect($dsn, $options);
if (PEAR::isError($db)) {
die($db->getMessage());
}
//
// return the requested DB resultset
Function getQueryData($query){
//
// Proceed with query...
$result =& $db->query($query);
//
// Check that result has no error
if (PEAR::isError($result)) {
die($res->getMessage());
}
return $result;
}

So in my main php file 'index.php' I would have the include for
'openDB.php' and eventually the reference to $dsn as in:

s->loadQuery($dsn, $category_dropdown_select);
where
s->loadQuery($db, $category_dropdown_select);
works and $dsn does not.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 11 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.