Re: [PHP-DB] Populating multi-select list from mysql

2002-06-21 Thread Jason Wong

On Friday 21 June 2002 10:31, bob wrote:
 Hi all,

 I'm having problems getting my multi-select list populated from a mysql
 table. There is a table called categories with 2 columns (id and category).
 I want to get all the items (category) and list them in the multi-select
 list box.

 This is the code I have so far:

 $sql = SELECT category FROM categories;

 $result = mysql_query($sql, $connection);

 while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$category = $row['category'];
$category_list .= $category;
}
 ?

Here your $category_list will be a string like 'Category1Category2...', which 
is probably not what you want.


 select name=category_list_array[] multiple size=10
 ?
 for ($i=0; $icount($category_list); $i++) {
 ?
   option value=?=$category_list[$i]??=$category_list[$i]?/option

 ?}?
 /select


 Now, if I echo $category_list to the page I can see I have the correct
 data, I just can't get it into the list box. I've seem to hit a wall on any
 different ways to try and make this work. What am I doing wrong?

Instead of doing two loops (while and for) just have a single while loop, 
build your option value... inside the while loop.

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
NOWPRINT. NOWPRINT. Clemclone, back to the shadows again.
- The Firesign Theater
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Populating multi-select list from mysql

2002-06-21 Thread Gary . Every



Hi all,

I'm having problems getting my multi-select list populated from a mysql
table. There is a table called categories with 2 columns (id and category).
I want to get all the items (category) and list them in the multi-select
list box.

This is the code I have so far:

$sql = SELECT category FROM categories;

$result = mysql_query($sql, $connection);

//Try This instead of the while statement
foreach($result as $row) {
echo 'OPTION VALUE=' . $row['category'] . '' . $row['category'];
}
echo '/select';





while ($row = mysql_fetch_array($result)) {
   $id = $row['id'];
   $category = $row['category'];
   $category_list .= $category;
   }
?


select name=category_list_array[] multiple size=10
?
for ($i=0; $icount($category_list); $i++) {
?
  option value=?=$category_list[$i]??=$category_list[$i]?/option

?}?
/select


Now, if I echo $category_list to the page I can see I have the correct data,
I just can't get it into the list box. I've seem to hit a wall on any
different ways to try and make this work. What am I doing wrong?

Thanks.

Rob.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Populating multi-select list from mysql

2002-06-21 Thread Ryan Jameson (USA)

You're logic seems to make sense. The output (page source) you are getting would help. 
:-)
 Ryan

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: Friday, June 21, 2002 10:06 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Populating multi-select list from mysql




Hi all,

I'm having problems getting my multi-select list populated from a mysql
table. There is a table called categories with 2 columns (id and category).
I want to get all the items (category) and list them in the multi-select
list box.

This is the code I have so far:

$sql = SELECT category FROM categories;

$result = mysql_query($sql, $connection);

//Try This instead of the while statement
foreach($result as $row) {
echo 'OPTION VALUE=' . $row['category'] . '' . $row['category'];
}
echo '/select';





while ($row = mysql_fetch_array($result)) {
   $id = $row['id'];
   $category = $row['category'];
   $category_list .= $category;
   }
?


select name=category_list_array[] multiple size=10
?
for ($i=0; $icount($category_list); $i++) {
?
  option value=?=$category_list[$i]??=$category_list[$i]?/option

?}?
/select


Now, if I echo $category_list to the page I can see I have the correct data,
I just can't get it into the list box. I've seem to hit a wall on any
different ways to try and make this work. What am I doing wrong?

Thanks.

Rob.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Populating multi-select list from mysql

2002-06-21 Thread Martin Clifford

Whenever you are having trouble with your PHP pages, always echo!  By doing this, you 
can see whether or not the query is formatted correctly, whether or not the variables 
are containing the values you think they are.  It's incredibly helpful, no matter what 
the situation.

Martin

 Ryan Jameson (USA) [EMAIL PROTECTED] 06/21/02 12:10PM 
You're logic seems to make sense. The output (page source) you are getting would help. 
:-)
 Ryan

-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED]] 
Sent: Friday, June 21, 2002 10:06 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED] 
Subject: RE: [PHP-DB] Populating multi-select list from mysql




Hi all,

I'm having problems getting my multi-select list populated from a mysql
table. There is a table called categories with 2 columns (id and category).
I want to get all the items (category) and list them in the multi-select
list box.

This is the code I have so far:

$sql = SELECT category FROM categories;

$result = mysql_query($sql, $connection);

//Try This instead of the while statement
foreach($result as $row) {
echo 'OPTION VALUE=' . $row['category'] . '' . $row['category'];
}
echo '/select';





while ($row = mysql_fetch_array($result)) {
   $id = $row['id'];
   $category = $row['category'];
   $category_list .= $category;
   }
?


select name=category_list_array[] multiple size=10
?
for ($i=0; $icount($category_list); $i++) {
?
  option value=?=$category_list[$i]??=$category_list[$i]?/option

?}?
/select


Now, if I echo $category_list to the page I can see I have the correct data,
I just can't get it into the list box. I've seem to hit a wall on any
different ways to try and make this work. What am I doing wrong?

Thanks.

Rob.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php 

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php 



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Populating multi-select list from mysql

2002-06-21 Thread bob

Thanks for all the help. I got it working using the following code from
Martin.

Rob.


$sql = SELECT category FROM categories;

$result = mysql_query($sql, $connection);

echo select name=\name here\\n;

while ($row = mysql_fetch_array($result)) {
   $id = $row['id'];
   $category = $row['category'];

   echo option value=\$category\$category/option\n;

   }

   echo /select\n\n;
?

-Original Message-
From: Martin Clifford [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 21, 2002 12:20 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED];
[EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Populating multi-select list from mysql


Whenever you are having trouble with your PHP pages, always echo!  By doing
this, you can see whether or not the query is formatted correctly, whether
or not the variables are containing the values you think they are.  It's
incredibly helpful, no matter what the situation.

Martin

 Ryan Jameson (USA) [EMAIL PROTECTED] 06/21/02 12:10PM 
You're logic seems to make sense. The output (page source) you are getting
would help. :-)
 Ryan

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: Friday, June 21, 2002 10:06 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Populating multi-select list from mysql




Hi all,

I'm having problems getting my multi-select list populated from a mysql
table. There is a table called categories with 2 columns (id and category).
I want to get all the items (category) and list them in the multi-select
list box.

This is the code I have so far:

$sql = SELECT category FROM categories;

$result = mysql_query($sql, $connection);

//Try This instead of the while statement
foreach($result as $row) {
echo 'OPTION VALUE=' . $row['category'] . '' . $row['category'];
}
echo '/select';





while ($row = mysql_fetch_array($result)) {
   $id = $row['id'];
   $category = $row['category'];
   $category_list .= $category;
   }
?


select name=category_list_array[] multiple size=10
?
for ($i=0; $icount($category_list); $i++) {
?
  option value=?=$category_list[$i]??=$category_list[$i]?/option

?}?
/select


Now, if I echo $category_list to the page I can see I have the correct data,
I just can't get it into the list box. I've seem to hit a wall on any
different ways to try and make this work. What am I doing wrong?

Thanks.

Rob.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php