getting items for select box from db... 
Author Message
 getting items for select box from db...

All,

I am using PHP connecting to a Postgre 7.2.3 DB.  I am setting up a web
form that will get info for select boxes from the db.  I've got it
working, but using the following code, the 1st record from the clergy
database is never displayed in my select list.  I know I could go in and
insert a dummy record in the database but that's just a band-aide, not
the real fix.  

I know it's gotta be something simple but I just can't figure out why
this is behaving in this way.

Thanks for all the great help!

Steve

                        <?php

                                $db = pg_connect("dbname=pom");

                                $clergy_query = "SELECT * FROM clergy";

                                $clergy_result = pg_exec($db, $clergy_query);

                                $clergy_array = pg_fetch_array($clergy_result);

                        ?>

                        Clergy
                        <select name="subscriber[clergy]" size=1>

                        <?php

                                while ($clergy = pg_fetch_array($clergy_result))

                                        {

                                                print("<option value=\"$clergy[0]\">$clergy[1], $clergy[2]\n");

                                        }

                        ?>

                        </select>



Mon, 30 May 2005 07:06:34 GMT  
 getting items for select box from db...

Quote:

> All,

> I am using PHP connecting to a Postgre 7.2.3 DB.  I am setting up a web
> form that will get info for select boxes from the db.  I've got it
> working, but using the following code, the 1st record from the clergy
> database is never displayed in my select list.  I know I could go in and
> insert a dummy record in the database but that's just a band-aide, not
> the real fix.  

> I know it's gotta be something simple but I just can't figure out why
> this is behaving in this way.

> Thanks for all the great help!

> Steve

Just a guess:

<?php

$db = pg_connect("dbname=pom");
$clergy_query = "SELECT * FROM clergy";
$clergy_result = pg_exec($db, $clergy_query);
$clergy_array = pg_fetch_array($clergy_result);
                ^^^^^^^^^^^^^^ here is you first record

while ($clergy = pg_fetch_array($clergy_result))
                 ^^^^^^^^^^^^^^so this is the second one

Remove the first fetch (what is it used for anyway) and your problems
may be solved.

--

  Daniel Tryba



Mon, 30 May 2005 16:36:12 GMT  
 getting items for select box from db...

Quote:


>> All,

>> I am using PHP connecting to a Postgre 7.2.3 DB.  I am setting up a web
>> form that will get info for select boxes from the db.  I've got it
>> working, but using the following code, the 1st record from the clergy
>> database is never displayed in my select list.  I know I could go in
>> and insert a dummy record in the database but that's just a band-aide,
>> not the real fix.

>> I know it's gotta be something simple but I just can't figure out why
>> this is behaving in this way.

>> Thanks for all the great help!

>> Steve

> Just a guess:

> <?php

> $db = pg_connect("dbname=pom");
> $clergy_query = "SELECT * FROM clergy"; $clergy_result = pg_exec($db,
> $clergy_query); $clergy_array = pg_fetch_array($clergy_result);
>                 ^^^^^^^^^^^^^^ here is you first record

> while ($clergy = pg_fetch_array($clergy_result))
>                  ^^^^^^^^^^^^^^so this is the second one

> Remove the first fetch (what is it used for anyway) and your problems
> may be solved.

Thanks!  That did it, started getting flustered and didn't clean up my
code as I tested several options.


Tue, 31 May 2005 00:12:24 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. HOW TO SELECT LIST BOX ITEM??

2. Multi-Select Items In Browse/List Box

3. Select item in Listview on Dialog box

4. Index of currently selected item in LIst box

5. selecting two items in two list boxes

6. getting index of the selected item

7. CGI : getting selected values in a select-object

8. Getting all items above/below of a selected item....................

9. Getting all items above/below of a selected item....................

10. Which item user selects in submenu

11. Selecting more than one item from a pick list

12. Using tabs to sort and select items

 

 
Powered by phpBB® Forum Software