HTML FORMS selected question

------=_Part_5708_1990230.1165185756003
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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!

------=_Part_5708_1990230.1165185756003
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I am having trouble getting values populated in my form... Here is what I got so far:<br><br>//The values that need to be selected<br>$result_ip=pg_query($dbconn,$test_query);<br><br><SELECT    NAME="ip[]" SIZE=10 MULTIPLE>
<br><?php <br>//This will show ALL values.<br>while($rows=pg_fetch_array($result)){<br>foreach ($options as $index => $option) {<br>    if ($rows[1]==$option)<br>    {<br>echo "<OptioN VALUE=\"$rows[0]\" selected=\"selected\">$rows[1]</Option> \n";
<br>break;<br>        }<br>else<br>{<br>    echo "<OPTION VALUE=\"$rows[0]\">$rows[1]</OPTION> \n"; <br>    break;<br>}<br>}<br>}<br><br>What am I doing wrong?<br><br>TIA!<br><br>

------=_Part_5708_1990230.1165185756003--
Mag Gam [ So, 03 Dezember 2006 23:42 ] [ ID #1555763 ]

Re: 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
Chris [ Mo, 04 Dezember 2006 00:08 ] [ ID #1555764 ]

Re: HTML FORMS selected question

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/

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org
Chris [ Mo, 04 Dezember 2006 00:17 ] [ ID #1555765 ]

Re: HTML FORMS selected question

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 [at] postgresql.org [mailto:pgsql-php-owner [at] postgresql.org]
On Behalf Of Chris
Sent: Sunday, December 03, 2006 4:08 PM
To: Mag Gam
Cc: pgsql-php [at] 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
Randy Moller [ Mo, 04 Dezember 2006 00:23 ] [ ID #1555766 ]

Re: HTML FORMS selected question

------=_Part_5876_15160297.1165189411076
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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 [at] 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 [at] postgresql.org [mailto:
> pgsql-php-owner [at] postgresql.org]
> On Behalf Of Chris
> Sent: Sunday, December 03, 2006 4:08 PM
> To: Mag Gam
> Cc: pgsql-php [at] 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
>

------=_Part_5876_15160297.1165189411076
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Randy + Chris:<br><br>Thx for the quick replies!<br><br>Chris: <br><br>$rows contain ip addresses (postgresql inet) type (example: 192.168.0.1)<br>$options contain ip addresses (postgresql inet0 type (example:
127.0.0.1)<br>(keep in mind) they are both arrays. $rows contact all ips, and $options contact the ip addresses that were selected<br><br>Randy:<br>I am not sure what you mean. The variables look right. I am getting no errors! Just the logic is messed up.
<br><br>HTH<br><br><br><br><br><div><span class="gmail_quote">On 12/3/06, <b class="gmail_sendername">Randy Moller</b> <zoomerz [at] comcast.net> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Maybe it's just a typo, but your pg_query is returning into the var<br>$result_ip, while your fetch is referencing var $result (without _ip).<br>Maybe that's just a typo for your question, but if not, that is at least one
<br>error.<br><br>Also, it would be helpful to know what error you're getting....<br><br>Randy Moller<br><br>-----Original Message-----<br>From: <a href="mailto:pgsql-php-owner [at] postgresql.org">pgsql-php-owner [at] postgresql.org
</a> [mailto:pgsql-php-owner [at] postgresql.org]<br>On Behalf Of Chris<br>Sent: Sunday, December 03, 2006 4:08 PM<br>To: Mag Gam<br>Cc: <a href="mailto:pgsql-php [at] postgresql.org">
pgsql-php [at] postgresql.org</a><br>Subject: Re: [PHP] HTML FORMS selected question<br><br>Mag Gam wrote:<br>> I am having trouble getting values populated in my form... Here is what<br>> I got so far:<br>><br>> //The values that need to be selected
<br>> $result_ip=pg_query($dbconn,$test_query);<br>><br>> <SELECT    NAME="ip[]" SIZE=10 MULTIPLE><br>> <?php<br>> //This will show ALL values.<br>> while($rows=pg_fetch_array($result)){
<br>> foreach ($options as $index => $option) {<br>>     if ($rows[1]==$option)<br>>     {<br><br><br>What does $rows contain? What does $options contain?<br><br>You could also simplify this a little bit. I'd at least remove the
<br>foreach $options loop and use "in_array" - see php.net/in_array<br><br>while ($rows = pg_fetch_array($result)) {<br>   $selected = '';<br>   if (in_array($rows[1], $options)) {
<br>     $selected = ' SELECTED';<br>   }<br>   sprintf('<option value="%s"%s>%s</option>', $rows[1], $selected,<br>$rows[1]);<br>}<br><br>--<br>Postgresql & php tutorials<br><a href="http://www.designmagick.com/">
http://www.designmagick.com/</a><br><br>---------------------------(end of broadcast)---------------------------<br>TIP 6: explain analyze is your friend<br><br>--<br>No virus found in this incoming message.<br>Checked by AVG Free Edition.
<br>Version: 7.5.430 / Virus Database: 268.15.6/565 - Release Date: 12/2/2006<br>9:39 PM<br><br><br>--<br>No virus found in this outgoing message.<br>Checked by AVG Free Edition.<br>Version: 7.5.430 / Virus Database: 268.15.6
/565 - Release Date: 12/2/2006<br>9:39 PM<br><br><br><br>---------------------------(end of broadcast)---------------------------<br>TIP 6: explain analyze is your friend<br></blockquote></div><br>

------=_Part_5876_15160297.1165189411076--
Mag Gam [ Mo, 04 Dezember 2006 00:43 ] [ ID #1556655 ]

Re: HTML FORMS selected question

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/

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
Chris [ Mo, 04 Dezember 2006 00:48 ] [ ID #1556656 ]

Re: HTML FORMS selected question

------=_Part_5924_16292896.1165190445596
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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 [at] 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/
>

------=_Part_5924_16292896.1165190445596
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Chris + Randy:<br><br>Sorry, I may of forgetten to give you this:<br>$result = pg_query($dbconn, "select id,address from ip");<br><br>This is right before the:<br>$options=pg_fetch_array($result_ip);<br><br>so, my $results is really all the ip addresses ($rows after I perform the pg_fetch_array).
<br><br>I will add the var_dump to see it (never done it before, I will do some googling :) )<br><br><br><br><br><br><br><div><span class="gmail_quote">On 12/3/06, <b class="gmail_sendername">Chris</b> <<a href="mailto:dmagick [at] gmail.com">
dmagick [at] gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Mag Gam wrote:<br>> Randy + Chris:<br>><br>> Thx for the quick replies!
<br>><br>> Chris:<br>><br>> $rows contain ip addresses (postgresql inet) type (example: 192.168.0.1<br>> <http://192.168.0.1>)<br>> $options contain ip addresses (postgresql inet0 type (example:
127.0.0.1<br>> <http://127.0.0.1>)<br>> (keep in mind) they are both arrays. $rows contact all ips, and $options<br>> contact the ip addresses that were selected
<br>><br>> Randy:<br>> I am not sure what you mean. The variables look right. I am getting no<br>> errors! Just the logic is messed up.<br><br>I think Randy's right.<br><br>At the top you have:<br><br>//The values that need to be selected
<br>$result_ip=pg_query($dbconn,$test_query);<br>^^^^^^^^^<br>but you are doing this:<br><br>while ($row = pg_fetch_array($result)) {<br><br><br>$result_ip  at the top, $result in the second bit.<br><br><br>If you don't see errors, turn up error reporting & display errors:
<br><br>error_reporting(E_ALL);<br>ini_set('display_errors', true);<br><br><br>Also that's not what I meant. I meant add a var_dump or print_r at each<br>stage to see what you are *really* getting from the code.<br><br><br>
--<br>Postgresql & php tutorials<br>http://www.designmagick.com/<br></blockquote></div><br>

------=_Part_5924_16292896.1165190445596--
Mag Gam [ Mo, 04 Dezember 2006 01:00 ] [ ID #1556657 ]

Re: HTML FORMS selected question

This is a multi-part message in MIME format.

------=_NextPart_000_001E_01C716FF.BDB696C0
Content-Type: text/plain;
charset="windows-1250"
Content-Transfer-Encoding: quoted-printable

Ok, I think you are misunderstanding the process:



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



$result =3D pg_query($dbconn, =93select=85=94) , so,



$result now is a =93resource reference=94 which contains the =
=93result=94 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 =93array=94, you now use $result like this:



$myArray =3D pg_fetch_array($result);



Now $myArray is the actual =93row/s=94 you returned in $result.



Does that make sense?



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



Hope that helps!

Randy

_____

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



Chris + Randy:

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

This is right before the:
$options=3Dpg_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 [at] gmail.com" =
dmagick [at] 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=3Dpg_query($dbconn,$test_query);
^^^^^^^^^
but you are doing this:

while ($row =3D 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


------=_NextPart_000_001E_01C716FF.BDB696C0
Content-Type: text/html;
charset="windows-1250"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dwindows-1250">


<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
..shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
[at] font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:blue;
text-decoration:underline;}
p
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman";}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:Arial;
color:navy;}
[at] page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
/* List Definitions */
[at] list l0
{mso-list-id:777137940;
mso-list-type:hybrid;
mso-list-template-ids:65710488 67698703 67698713 67698715 67698703 =
67698713 67698715 67698703 67698713 67698715;}
[at] list l0:level1
{mso-level-tab-stop:.5in;
mso-level-number-position:left;
text-indent:-.25in;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dblue>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Ok, I think you are =
misunderstanding the
process:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<ol style=3D'margin-top:0in' start=3D1 type=3D1>
<li class=3DMsoNormal style=3D'color:navy;mso-list:l0 level1 =
lfo1'><font size=3D2
color=3Dnavy face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>first,
you are querying a database (I assume a postgres db) like =
this:<o:p></o:p></span></font></li>
</ol>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>$result =3D pg_query($dbconn, =
“select…”) ,
so,<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>$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:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>$myArray =3D =
pg_fetch_array($result);<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Now $myArray is the actual =
“row/s” you
returned in $result.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Does that make =
sense?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>So, when you first query, $result =
(or
$result_ip) =3D 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.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Hope that =
helps!<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Randy<o:p></o:p></span></font></p>

<div>

<div class=3DMsoNormal align=3Dcenter style=3D'text-align:center'><font =
size=3D3
face=3D"Times New Roman"><span style=3D'font-size:12.0pt'>

<hr size=3D2 width=3D"100%" align=3Dcenter tabindex=3D-1>

</span></font></div>

<p class=3DMsoNormal><b><font size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font =
size=3D2
face=3DTahoma><span style=3D'font-size:10.0pt;font-family:Tahoma'>
pgsql-php-owner [at] postgresql.org [mailto:pgsql-php-owner [at] postgresql.org] =
<b><span
style=3D'font-weight:bold'>On Behalf Of </span></b>Mag Gam<br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Sunday, December =
03, 2006
5:01 PM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> Chris<br>
<b><span style=3D'font-weight:bold'>Cc:</span></b> Randy Moller;
pgsql-php [at] postgresql.org<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> Re: [PHP] HTML =
FORMS
selected question</span></font><o:p></o:p></p>

</div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p> </o:p></span></font></p>

<p class=3DMsoNormal style=3D'margin-bottom:12.0pt'><font size=3D3
face=3D"Times New Roman"><span style=3D'font-size:12.0pt'>Chris + =
Randy:<br>
<br>
Sorry, I may of forgetten to give you this:<br>
$result =3D pg_query($dbconn, "select id,address from =
ip");<br>
<br>
This is right before the:<br>
$options=3Dpg_fetch_array($result_ip);<br>
<br>
so, my $results is really all the ip addresses ($rows after I perform =
the
pg_fetch_array). <br>
<br>
I will add the var_dump to see it (never done it before, I will do some
googling :) )<br>
<br>
<br>
<br>
<br>
<br>
<o:p></o:p></span></font></p>

<div>

<p class=3DMsoNormal><span class=3Dgmailquote><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>On 12/3/06, <b><span =
style=3D'font-weight:bold'>Chris</span></b>
<<a href=3D"mailto:dmagick [at] gmail.com"> dmagick [at] gmail.com</a>> =
wrote:</span></font></span><o:p></o:p></p>

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

</div>

<p class=3DMsoNormal style=3D'margin-bottom:12.0pt'><font size=3D3
face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'><o:p> </o:p></span></font></p>

<p><font size=3D2 face=3D"Times New Roman"><span =
style=3D'font-size:10.0pt'>--<br>
No virus found in this incoming message.<br>
Checked by AVG Free Edition.<br>
Version: 7.5.430 / Virus Database: 268.15.6/565 - Release Date: =
12/2/2006 9:39
PM</span></font><o:p></o:p></p>

</div>

</body>

</html>
<BR>

<P><FONT SIZE=3D2>--<BR>
No virus found in this outgoing message.<BR>
Checked by AVG Free Edition.<BR>
Version: 7.5.430 / Virus Database: 268.15.6/565 - Release Date: =
12/2/2006 9:39 PM<BR>
</FONT> </P>

------=_NextPart_000_001E_01C716FF.BDB696C0--
Randy Moller [ Mo, 04 Dezember 2006 01:23 ] [ ID #1556658 ]

Re: HTML FORMS selected question

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/

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
Chris [ Mo, 04 Dezember 2006 01:25 ] [ ID #1556659 ]

Re: HTML FORMS selected question

--0-436170247-1165255151=:11557
Content-Type: text/plain; charset=ascii
Content-Transfer-Encoding: quoted-printable

----- Original Message ----=0AFrom: Mag Gam <magawake [at] gmail.com>=0ATo: pgsq=
l-php [at] postgresql.org=0ASent: Sunday, December 3, 2006 2:42:36 PM=0ASubject:=
[PHP] HTML FORMS selected question=0A=0AI am having trouble getting values=
populated in my form... Here is what I got so far:=0A=0A//The values that =
need to be selected=0A$result_ip=3Dpg_query($dbconn,$test_query);=0A=0A<SEL=
ECT NAME=3D"ip[]" SIZE=3D10 MULTIPLE>=0A=0A<?php =0A//This will show ALL=
values.=0Awhile($rows=3Dpg_fetch_array($result)){=0Aforeach ($options as $=
index =3D> $option) {=0A if ($rows[1]=3D=3D$option)=0A {=0Aecho "<Opt=
ioN VALUE=3D\"$rows[0]\" selected=3D\"selected\">$rows[1]</Option> \n"; =0A=
=0Abreak;=0A }=0Aelse=0A{=0A echo "<OPTION VALUE=3D\"$rows[0]\">$=
rows[1]</OPTION> \n"; =0A break;=0A}=0A}=0A}=0A=0AWhat am I doing wrong?=
=0A=0ATIA!=0A=0A---------------------------=0A=0AMag, 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.=0A=0Ai recommend you loo=
k into learning a forms class. the code will be much cleaner and the thoug=
ht process is much more obvious. the icing on the cake is the increased fu=
nctionality you will get "out of the box" because some smart person coded i=
t 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 for=
m give focus to the first element via javascript. there is some ajaxy stuf=
f i haven't learned yet, but it is available.=0A=0Ai 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 commerc=
ial applications. there are others, too. i believe pear has one, along wi=
th some other functionality.=0A=0Ai'm very glad i went with a forms class i=
nstead of "htmling" it all. i think you will be, too.=0A=0AManuel has a ya=
hoo mailing list that is very helpful and reasonably active. Most question=
s are answered within a day or so.=0A=0Agood luck.=0A=0A=0A=0A=0A=0A =0A___=
____________________________________________________________ _______________=
______=0ADo you Yahoo!?=0AEveryone is raving about the all-new Yahoo! Mail =
beta.=0Ahttp://new.mail.yahoo.com
--0-436170247-1165255151=:11557
Content-Type: text/html; charset=ascii
Content-Transfer-Encoding: quoted-printable

<html><head><style type=3D"text/css"><!-- DIV {margin:0px;} --></style></he=
ad><body><div style=3D"font-family:times new roman, new york, times, serif;=
font-size:10pt"><div style=3D"font-family: times new roman,new york,times,s=
erif; font-size: 10pt;">----- Original Message ----<br><div style=3D"font-f=
amily: times new roman,new york,times,serif; font-size: 12pt;">From: Mag Ga=
m <magawake [at] gmail.com><br>To: pgsql-php [at] postgresql.org<br>Sent: Sunda=
y, December 3, 2006 2:42:36 PM<br>Subject: [PHP] HTML FORMS selected questi=
on<br><br>I am having trouble getting values populated in my form... Here i=
s what I got so far:<br><br>//The values that need to be selected<br>$resul=
t_ip=3Dpg_query($dbconn,$test_query);<br><br><SELECT    N=
AME=3D"ip[]" SIZE=3D10 MULTIPLE>=0A<br><?php <br>//This will show ALL=
values.<br>while($rows=3Dpg_fetch_array($result)){<br>foreach ($options as=
$index =3D> $option) {<br>    if ($rows[1]=3D=3D$option)=
<br>    {<br>echo "<OptioN VALUE=3D\"$rows[0]\" selected=
=3D\"selected\">$rows[1]</Option> \n"; =0A<br>break;<br> &nbs=
p;      }<br>else<br>{<br>    echo "<=
OPTION VALUE=3D\"$rows[0]\">$rows[1]</OPTION> \n"; <br>  =
;  break;<br>}<br>}<br>}<br><br>What am I doing wrong?<br><br>TIA!<br>=
<br>---------------------------<br><br>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.<br><br>i recommend you look into l=
earning 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 i=
s some ajaxy stuff i haven't learned yet, but it is
available.<br><br>i use Manuel Lemos' free forms generation and validation=
class which can be found on phpclasses.org.  iirc, the license is suc=
h that it can be included in proprietary commercial applications.  the=
re are others, too.  i believe pear has one, along with some other fun=
ctionality.<br><br>i'm very glad i went with a forms class instead of "html=
ing" it all.  i think you will be, too.<br><br>Manuel has a yahoo mail=
ing list that is very helpful and reasonably active.  Most questions a=
re answered within a day or so.<br><br>good luck.<br></div></div></div><br>=
=0A=0A<hr size=3D1>Have a burning question? Go to <a href=3D"http://answers=
..yahoo.com/;_ylc=3DX3oDMTFvbGNhMGE3BF9TAzM5NjU0NTEwOARfcwMz OTY1NDUxMDMEc2Vj=
A21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx">Yahoo! Answers</a> and get answers fr=
om real people who know.</body></html>
--0-436170247-1165255151=:11557--
operationsengineer1 [ Mo, 04 Dezember 2006 18:59 ] [ ID #1556660 ]
Datenbanken » gmane.comp.db.postgresql.php » HTML FORMS selected question

Vorheriges Thema: cant conect to dynamic host-URL
Nächstes Thema: Re: Unsubscribe - Instructions