pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
HTML FORMS selected question
10+ messages / 4 participants
[nested] [flat]

* HTML FORMS selected question
@ 2006-12-03 22:42 Mag Gam <magawake@gmail.com>
  2006-12-03 23:08 ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Mag Gam @ 2006-12-03 22:42 UTC (permalink / raw)
  To: pgsql-php

I am having trouble getting values populated in my form... Here is what I
got so far:

//The values that need to be selected
$result_ip=pg_query($dbconn,$test_query);

<SELECT    NAME="ip[]" SIZE=10 MULTIPLE>
<?php
//This will show ALL values.
while($rows=pg_fetch_array($result)){
foreach ($options as $index => $option) {
    if ($rows[1]==$option)
    {
echo "<OptioN VALUE=\"$rows[0]\" selected=\"selected\">$rows[1]</Option>
\n";
break;
        }
else
{
    echo "<OPTION VALUE=\"$rows[0]\">$rows[1]</OPTION> \n";
    break;
}
}
}

What am I doing wrong?

TIA!

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: HTML FORMS selected question
  2006-12-03 22:42 HTML FORMS selected question Mag Gam <magawake@gmail.com>
@ 2006-12-03 23:08 ` Chris <dmagick@gmail.com>
  2006-12-03 23:17   ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  2006-12-03 23:23   ` Re: HTML FORMS selected question Randy Moller <zoomerz@comcast.net>
  0 siblings, 2 replies; 10+ messages in thread

From: Chris @ 2006-12-03 23:08 UTC (permalink / raw)
  To: Mag Gam <magawake@gmail.com>; +Cc: pgsql-php

Mag Gam wrote:
> I am having trouble getting values populated in my form... Here is what 
> I got so far:
> 
> //The values that need to be selected
> $result_ip=pg_query($dbconn,$test_query);
> 
> <SELECT    NAME="ip[]" SIZE=10 MULTIPLE>
> <?php
> //This will show ALL values.
> while($rows=pg_fetch_array($result)){
> foreach ($options as $index => $option) {
>     if ($rows[1]==$option)
>     {


What does $rows contain? What does $options contain?

You could also simplify this a little bit. I'd at least remove the 
foreach $options loop and use "in_array" - see php.net/in_array

while ($rows = pg_fetch_array($result)) {
   $selected = '';
   if (in_array($rows[1], $options)) {
     $selected = ' SELECTED';
   }
   sprintf('<option value="%s"%s>%s</option>', $rows[1], $selected, 
$rows[1]);
}

-- 
Postgresql & php tutorials
http://www.designmagick.com/



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: HTML FORMS selected question
  2006-12-03 22:42 HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:08 ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
@ 2006-12-03 23:17   ` Chris <dmagick@gmail.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Chris @ 2006-12-03 23:17 UTC (permalink / raw)
  To: Mag Gam <magawake@gmail.com>; +Cc: pgsql-php

Please CC the list so they can suggest things and learn as well.

Mag Gam wrote:
> Hi Chris:
> 
> $rows is an array of all the values
> $options is an array of all the values selected

I meant can you give an example of what they both contain?

I know what they *should* contain - what do they *actually* contain?

-- 
Postgresql & php tutorials
http://www.designmagick.com/



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: HTML FORMS selected question
  2006-12-03 22:42 HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:08 ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
@ 2006-12-03 23:23   ` Randy Moller <zoomerz@comcast.net>
  2006-12-03 23:43     ` Re: HTML FORMS selected question Mag Gam <magawake@gmail.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Randy Moller @ 2006-12-03 23:23 UTC (permalink / raw)
  To: 'Mag Gam' <magawake@gmail.com>; +Cc: pgsql-php

Maybe it's just a typo, but your pg_query is returning into the var 
$result_ip, while your fetch is referencing var $result (without _ip). 
Maybe that's just a typo for your question, but if not, that is at least one
error.
 
Also, it would be helpful to know what error you're getting....

Randy Moller

-----Original Message-----
From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org]
On Behalf Of Chris
Sent: Sunday, December 03, 2006 4:08 PM
To: Mag Gam
Cc: pgsql-php@postgresql.org
Subject: Re: [PHP] HTML FORMS selected question

Mag Gam wrote:
> I am having trouble getting values populated in my form... Here is what 
> I got so far:
> 
> //The values that need to be selected
> $result_ip=pg_query($dbconn,$test_query);
> 
> <SELECT    NAME="ip[]" SIZE=10 MULTIPLE>
> <?php
> //This will show ALL values.
> while($rows=pg_fetch_array($result)){
> foreach ($options as $index => $option) {
>     if ($rows[1]==$option)
>     {


What does $rows contain? What does $options contain?

You could also simplify this a little bit. I'd at least remove the 
foreach $options loop and use "in_array" - see php.net/in_array

while ($rows = pg_fetch_array($result)) {
   $selected = '';
   if (in_array($rows[1], $options)) {
     $selected = ' SELECTED';
   }
   sprintf('<option value="%s"%s>%s</option>', $rows[1], $selected, 
$rows[1]);
}

-- 
Postgresql & php tutorials
http://www.designmagick.com/

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.15.6/565 - Release Date: 12/2/2006
9:39 PM
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.15.6/565 - Release Date: 12/2/2006
9:39 PM
 




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: HTML FORMS selected question
  2006-12-03 22:42 HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:08 ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  2006-12-03 23:23   ` Re: HTML FORMS selected question Randy Moller <zoomerz@comcast.net>
@ 2006-12-03 23:43     ` Mag Gam <magawake@gmail.com>
  2006-12-03 23:48       ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Mag Gam @ 2006-12-03 23:43 UTC (permalink / raw)
  To: Randy Moller <zoomerz@comcast.net>; +Cc: pgsql-php

Randy + Chris:

Thx for the quick replies!

Chris:

$rows contain ip addresses (postgresql inet) type (example: 192.168.0.1)
$options contain ip addresses (postgresql inet0 type (example: 127.0.0.1)
(keep in mind) they are both arrays. $rows contact all ips, and $options
contact the ip addresses that were selected

Randy:
I am not sure what you mean. The variables look right. I am getting no
errors! Just the logic is messed up.

HTH




On 12/3/06, Randy Moller <zoomerz@comcast.net> wrote:
>
> Maybe it's just a typo, but your pg_query is returning into the var
> $result_ip, while your fetch is referencing var $result (without _ip).
> Maybe that's just a typo for your question, but if not, that is at least
> one
> error.
>
> Also, it would be helpful to know what error you're getting....
>
> Randy Moller
>
> -----Original Message-----
> From: pgsql-php-owner@postgresql.org [mailto:
> pgsql-php-owner@postgresql.org]
> On Behalf Of Chris
> Sent: Sunday, December 03, 2006 4:08 PM
> To: Mag Gam
> Cc: pgsql-php@postgresql.org
> Subject: Re: [PHP] HTML FORMS selected question
>
> Mag Gam wrote:
> > I am having trouble getting values populated in my form... Here is what
> > I got so far:
> >
> > //The values that need to be selected
> > $result_ip=pg_query($dbconn,$test_query);
> >
> > <SELECT    NAME="ip[]" SIZE=10 MULTIPLE>
> > <?php
> > //This will show ALL values.
> > while($rows=pg_fetch_array($result)){
> > foreach ($options as $index => $option) {
> >     if ($rows[1]==$option)
> >     {
>
>
> What does $rows contain? What does $options contain?
>
> You could also simplify this a little bit. I'd at least remove the
> foreach $options loop and use "in_array" - see php.net/in_array
>
> while ($rows = pg_fetch_array($result)) {
>    $selected = '';
>    if (in_array($rows[1], $options)) {
>      $selected = ' SELECTED';
>    }
>    sprintf('<option value="%s"%s>%s</option>', $rows[1], $selected,
> $rows[1]);
> }
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.430 / Virus Database: 268.15.6/565 - Release Date: 12/2/2006
> 9:39 PM
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.430 / Virus Database: 268.15.6/565 - Release Date: 12/2/2006
> 9:39 PM
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: HTML FORMS selected question
  2006-12-03 22:42 HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:08 ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  2006-12-03 23:23   ` Re: HTML FORMS selected question Randy Moller <zoomerz@comcast.net>
  2006-12-03 23:43     ` Re: HTML FORMS selected question Mag Gam <magawake@gmail.com>
@ 2006-12-03 23:48       ` Chris <dmagick@gmail.com>
  2006-12-04 00:00         ` Re: HTML FORMS selected question Mag Gam <magawake@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Chris @ 2006-12-03 23:48 UTC (permalink / raw)
  To: Mag Gam <magawake@gmail.com>; +Cc: Randy Moller <zoomerz@comcast.net>; pgsql-php

Mag Gam wrote:
> Randy + Chris:
> 
> Thx for the quick replies!
> 
> Chris:
> 
> $rows contain ip addresses (postgresql inet) type (example: 192.168.0.1 
> <http://192.168.0.1;)
> $options contain ip addresses (postgresql inet0 type (example: 127.0.0.1 
> <http://127.0.0.1;)
> (keep in mind) they are both arrays. $rows contact all ips, and $options 
> contact the ip addresses that were selected
> 
> Randy:
> I am not sure what you mean. The variables look right. I am getting no 
> errors! Just the logic is messed up.

I think Randy's right.

At the top you have:

//The values that need to be selected
$result_ip=pg_query($dbconn,$test_query);
^^^^^^^^^
but you are doing this:

while ($row = pg_fetch_array($result)) {


$result_ip  at the top, $result in the second bit.


If you don't see errors, turn up error reporting & display errors:

error_reporting(E_ALL);
ini_set('display_errors', true);


Also that's not what I meant. I meant add a var_dump or print_r at each 
stage to see what you are *really* getting from the code.


-- 
Postgresql & php tutorials
http://www.designmagick.com/



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: HTML FORMS selected question
  2006-12-03 22:42 HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:08 ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  2006-12-03 23:23   ` Re: HTML FORMS selected question Randy Moller <zoomerz@comcast.net>
  2006-12-03 23:43     ` Re: HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:48       ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
@ 2006-12-04 00:00         ` Mag Gam <magawake@gmail.com>
  2006-12-04 00:23           ` Re: HTML FORMS selected question Randy Moller <zoomerz@comcast.net>
  2006-12-04 00:25           ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  0 siblings, 2 replies; 10+ messages in thread

From: Mag Gam @ 2006-12-04 00:00 UTC (permalink / raw)
  To: Chris <dmagick@gmail.com>; +Cc: Randy Moller <zoomerz@comcast.net>; pgsql-php

Chris + Randy:

Sorry, I may of forgetten to give you this:
$result = pg_query($dbconn, "select id,address from ip");

This is right before the:
$options=pg_fetch_array($result_ip);

so, my $results is really all the ip addresses ($rows after I perform the
pg_fetch_array).

I will add the var_dump to see it (never done it before, I will do some
googling :) )






On 12/3/06, Chris <dmagick@gmail.com> wrote:
>
> Mag Gam wrote:
> > Randy + Chris:
> >
> > Thx for the quick replies!
> >
> > Chris:
> >
> > $rows contain ip addresses (postgresql inet) type (example: 192.168.0.1
> > <http://192.168.0.1;)
> > $options contain ip addresses (postgresql inet0 type (example: 127.0.0.1
> > <http://127.0.0.1;)
> > (keep in mind) they are both arrays. $rows contact all ips, and $options
> > contact the ip addresses that were selected
> >
> > Randy:
> > I am not sure what you mean. The variables look right. I am getting no
> > errors! Just the logic is messed up.
>
> I think Randy's right.
>
> At the top you have:
>
> //The values that need to be selected
> $result_ip=pg_query($dbconn,$test_query);
> ^^^^^^^^^
> but you are doing this:
>
> while ($row = pg_fetch_array($result)) {
>
>
> $result_ip  at the top, $result in the second bit.
>
>
> If you don't see errors, turn up error reporting & display errors:
>
> error_reporting(E_ALL);
> ini_set('display_errors', true);
>
>
> Also that's not what I meant. I meant add a var_dump or print_r at each
> stage to see what you are *really* getting from the code.
>
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: HTML FORMS selected question
  2006-12-03 22:42 HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:08 ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  2006-12-03 23:23   ` Re: HTML FORMS selected question Randy Moller <zoomerz@comcast.net>
  2006-12-03 23:43     ` Re: HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:48       ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  2006-12-04 00:00         ` Re: HTML FORMS selected question Mag Gam <magawake@gmail.com>
@ 2006-12-04 00:23           ` Randy Moller <zoomerz@comcast.net>
  1 sibling, 0 replies; 10+ messages in thread

From: Randy Moller @ 2006-12-04 00:23 UTC (permalink / raw)
  To: 'Mag Gam' <magawake@gmail.com>; +Cc: pgsql-php

Ok, I think you are misunderstanding the process:

 

1.	first, you are querying a database (I assume a postgres db) like
this:

 

$result = pg_query($dbconn, “select…”) , so,

 

$result now is a “resource reference” which contains the “result” of the
query. However, now you need to tell php to return the contents of that
resource to you (you can return in either an indexed, associative, or object
array). So, to get your “array”, you now use $result like this:

 

$myArray = pg_fetch_array($result);

 

Now $myArray is the actual “row/s” you returned in $result.

 

Does that make sense?

 

So, when you first query, $result (or $result_ip) = pg_query(conn, sql), you
need to be consistent with your variables. Either use $result_ip, or
$result, but not both….My guess is that’s your problem.

 

Hope that helps!

Randy

   _____  

From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org]
On Behalf Of Mag Gam
Sent: Sunday, December 03, 2006 5:01 PM
To: Chris
Cc: Randy Moller; pgsql-php@postgresql.org
Subject: Re: [PHP] HTML FORMS selected question

 

Chris + Randy:

Sorry, I may of forgetten to give you this:
$result = pg_query($dbconn, "select id,address from ip");

This is right before the:
$options=pg_fetch_array($result_ip);

so, my $results is really all the ip addresses ($rows after I perform the
pg_fetch_array). 

I will add the var_dump to see it (never done it before, I will do some
googling :) )







On 12/3/06, Chris <HYPERLINK "mailto:dmagick@gmail.com" dmagick@gmail.com>
wrote:

Mag Gam wrote:
> Randy + Chris:
>
> Thx for the quick replies! 
>
> Chris:
>
> $rows contain ip addresses (postgresql inet) type (example: HYPERLINK
"http://192.168.0.1"192.168.0.1
> <HYPERLINK "http://192.168.0.1"http://192.168.0.1;)
> $options contain ip addresses (postgresql inet0 type (example: HYPERLINK
"http://127.0.0.1"127.0.0.1
> <HYPERLINK "http://127.0.0.1"http://127.0.0.1;)
> (keep in mind) they are both arrays. $rows contact all ips, and $options
> contact the ip addresses that were selected 
>
> Randy:
> I am not sure what you mean. The variables look right. I am getting no
> errors! Just the logic is messed up.

I think Randy's right.

At the top you have:

//The values that need to be selected 
$result_ip=pg_query($dbconn,$test_query);
^^^^^^^^^
but you are doing this:

while ($row = pg_fetch_array($result)) {


$result_ip  at the top, $result in the second bit.


If you don't see errors, turn up error reporting & display errors: 

error_reporting(E_ALL);
ini_set('display_errors', true);


Also that's not what I meant. I meant add a var_dump or print_r at each
stage to see what you are *really* getting from the code.


--
Postgresql & php tutorials
HYPERLINK "http://www.designmagick.com/"http://www.designmagick.com/

 

--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.15.6/565 - Release Date: 12/2/2006
9:39 PM


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.15.6/565 - Release Date: 12/2/2006
9:39 PM
 

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: HTML FORMS selected question
  2006-12-03 22:42 HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:08 ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  2006-12-03 23:23   ` Re: HTML FORMS selected question Randy Moller <zoomerz@comcast.net>
  2006-12-03 23:43     ` Re: HTML FORMS selected question Mag Gam <magawake@gmail.com>
  2006-12-03 23:48       ` Re: HTML FORMS selected question Chris <dmagick@gmail.com>
  2006-12-04 00:00         ` Re: HTML FORMS selected question Mag Gam <magawake@gmail.com>
@ 2006-12-04 00:25           ` Chris <dmagick@gmail.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Chris @ 2006-12-04 00:25 UTC (permalink / raw)
  To: Mag Gam <magawake@gmail.com>; +Cc: Randy Moller <zoomerz@comcast.net>; pgsql-php

Mag Gam wrote:
> Chris + Randy:
> 
> Sorry, I may of forgetten to give you this:
> $result = pg_query($dbconn, "select id,address from ip");
> 
> This is right before the:
> $options=pg_fetch_array($result_ip);
> 
> so, my $results is really all the ip addresses ($rows after I perform 
> the pg_fetch_array).
> 
> I will add the var_dump to see it (never done it before, I will do some 
> googling :) )

After your query add it:

$result = pg_query(....)
var_dump($result);

if that's not a "resource" then you have a problem with your query. Use 
pg_last_error to work it out.


Inside your loop, add it:

while ($row = pg_fetch_array($result)) {
   var_dump($row);
}

-- 
Postgresql & php tutorials
http://www.designmagick.com/



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: HTML FORMS selected question
@ 2006-12-04 17:59 operationsengineer1@yahoo.com
  0 siblings, 0 replies; 10+ messages in thread

From: operationsengineer1@yahoo.com @ 2006-12-04 17:59 UTC (permalink / raw)
  To: Mag Gam <magawake@gmail.com>; pgsql-php

----- Original Message ----
From: Mag Gam <magawake@gmail.com>
To: pgsql-php@postgresql.org
Sent: Sunday, December 3, 2006 2:42:36 PM
Subject: [PHP] HTML FORMS selected question

I am having trouble getting values populated in my form... Here is what I got so far:

//The values that need to be selected
$result_ip=pg_query($dbconn,$test_query);

<SELECT    NAME="ip[]" SIZE=10 MULTIPLE>

<?php 
//This will show ALL values.
while($rows=pg_fetch_array($result)){
foreach ($options as $index => $option) {
    if ($rows[1]==$option)
    {
echo "<OptioN VALUE=\"$rows[0]\" selected=\"selected\">$rows[1]</Option> \n"; 

break;
        }
else
{
    echo "<OPTION VALUE=\"$rows[0]\">$rows[1]</OPTION> \n"; 
    break;
}
}
}

What am I doing wrong?

TIA!

---------------------------

Mag, i'm not sure what is wrong with the specific code, however, i'll make a suggestion that i think will help you more than just resolving this issue.

i recommend you look into learning a forms class.  the code will be much cleaner and the thought process is much more obvious.  the icing on the cake is the increased functionality you will get "out of the box" because some smart person coded it right into their forms class.  for example, i get client side and server side error checking and error message reporting.  i also get to have my form give focus to the first element via javascript.  there is some ajaxy stuff i haven't learned yet, but it is available.

i use Manuel Lemos' free forms generation and validation class which can be found on phpclasses.org.  iirc, the license is such that it can be included in proprietary commercial applications.  there are others, too.  i believe pear has one, along with some other functionality.

i'm very glad i went with a forms class instead of "htmling" it all.  i think you will be, too.

Manuel has a yahoo mailing list that is very helpful and reasonably active.  Most questions are answered within a day or so.

good luck.





 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2006-12-04 17:59 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-12-03 22:42 HTML FORMS selected question Mag Gam <magawake@gmail.com>
2006-12-03 23:08 ` Chris <dmagick@gmail.com>
2006-12-03 23:17   ` Chris <dmagick@gmail.com>
2006-12-03 23:23   ` Randy Moller <zoomerz@comcast.net>
2006-12-03 23:43     ` Mag Gam <magawake@gmail.com>
2006-12-03 23:48       ` Chris <dmagick@gmail.com>
2006-12-04 00:00         ` Mag Gam <magawake@gmail.com>
2006-12-04 00:23           ` Randy Moller <zoomerz@comcast.net>
2006-12-04 00:25           ` Chris <dmagick@gmail.com>
2006-12-04 17:59 Re: HTML FORMS selected question operationsengineer1@yahoo.com

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox