Re: [PHP] Enum table entry

2002-10-19 Thread Tom Rogers
Hi,

Saturday, October 19, 2002, 2:48:14 PM, you wrote:
SM Have a question that im trying to figure out how to resolve. I have a field type 
in mysql that is of the enum type. Unless youre familiar with Dungeons and Dragons, 
you wont get what the values
SM mean, but hopefully youll get the gist anyway. I have a column labelled school 
which holds an enum data type comprised of the values 1 through 40. From the website 
front end, where the data is
SM being entered, i want to display, ideally a series of checkboxes, otherwise a list 
which would allow a user to select multiple items in that will translate into this 
enum field. For instance, a
SM series of checkboxes with items such as abjuration, conjuration, divination, and 
others, which will all have a numeric value which gets plugged into the enum field. 
for instance, if a user
SM selected abjuration, and divination, it would be plugged into sql as 1, 3 (or 
however enum data is input into its column). That being the case how do i utilize php 
to get this to work? what kind
SM of form elements etc... The problem im seeing with checkboxes are that they are 
discreet and dont group together, so i cant get all the data to go into one column in 
mysql. Hopefully i havent
SM horribly confused the issue and some kind soul out there can tell me how to send 
this data across. As a double nice thing...how would you write it to pull the data 
back out...ie, convert 1, 3 to
SM show abjuration, divination? Thanks for the help in advance. 

 I have never used enum type but I am sure it is not what you want as
 it will only store one item from a predefined list not a list of
 items. What you need to do is create an array of the selected items,
 serialize() it to store in the database in a varchar or mediumtext if
 it going to get big. Then when you read it back unserialize and loop
 through all the options setting checked if it is in the array.
 To keep the checkboxes grouped name them like this:
 input type=checkbox name=school[1]
 input type=checkbox name=school[2]
 input type=checkbox name=school[3]

 That will show up as an array under $_POST['school']
 so you can serialize it as is and store it.

 ?
 if(isset($_POST['school'])) $school = serialize($_POST['school']);
 ?

 Playback is simple too

  ?
  $school = unserialize($row['school']);
  for($i = 1;$i  41;$i++){
 echo 'input type=checkbox name=school['.$i.']';
 if(isset($school[$i])) echo ' checked';
 echo '';
  }

  Un-checked boxes are not returned in the post and checked ones
  return Yes I think.



-- 
regards,
Tom


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




Re: [PHP] Enum table entry

2002-10-19 Thread John Nichel
You know, I didn't even think about serializing the array.  I have a 
table set up for spells, one for schools, and a linking table using the 
spell id and the school id(s).  I could have done without the linking 
table.  Some of you people are pretty freakin' smart. :)

One note though, when you pull the serialized data out, you may have to 
stripslashes before unserialize...

$school = unserialize ( stripslashes ( $row['school'] ) );

Tom Rogers wrote:
Hi,

Saturday, October 19, 2002, 2:48:14 PM, you wrote:
SM Have a question that im trying to figure out how to resolve. I have a field type in mysql that is of the enum type. Unless youre familiar with Dungeons and Dragons, you wont get what the values
SM mean, but hopefully youll get the gist anyway. I have a column labelled school which holds an enum data type comprised of the values 1 through 40. From the website front end, where the data is
SM being entered, i want to display, ideally a series of checkboxes, otherwise a list which would allow a user to select multiple items in that will translate into this enum field. For instance, a
SM series of checkboxes with items such as abjuration, conjuration, divination, and others, which will all have a numeric value which gets plugged into the enum field. for instance, if a user
SM selected abjuration, and divination, it would be plugged into sql as 1, 3 (or however enum data is input into its column). That being the case how do i utilize php to get this to work? what kind
SM of form elements etc... The problem im seeing with checkboxes are that they are discreet and dont group together, so i cant get all the data to go into one column in mysql. Hopefully i havent
SM horribly confused the issue and some kind soul out there can tell me how to send this data across. As a double nice thing...how would you write it to pull the data back out...ie, convert 1, 3 to
SM show abjuration, divination? Thanks for the help in advance. 

 I have never used enum type but I am sure it is not what you want as
 it will only store one item from a predefined list not a list of
 items. What you need to do is create an array of the selected items,
 serialize() it to store in the database in a varchar or mediumtext if
 it going to get big. Then when you read it back unserialize and loop
 through all the options setting checked if it is in the array.
 To keep the checkboxes grouped name them like this:
 input type=checkbox name=school[1]
 input type=checkbox name=school[2]
 input type=checkbox name=school[3]

 That will show up as an array under $_POST['school']
 so you can serialize it as is and store it.

 ?
 if(isset($_POST['school'])) $school = serialize($_POST['school']);
 ?

 Playback is simple too

  ?
  $school = unserialize($row['school']);
  for($i = 1;$i  41;$i++){
 echo 'input type=checkbox name=school['.$i.']';
 if(isset($school[$i])) echo ' checked';
 echo '';
  }

  Un-checked boxes are not returned in the post and checked ones
  return Yes I think.






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




[PHP] Enum table entry

2002-10-19 Thread Shiloh Madsen
Have a question that im trying to figure out how to resolve. I have a field type in 
mysql that is of the enum type. Unless youre familiar with Dungeons and Dragons, you 
wont get what the values mean, but hopefully youll get the gist anyway. I have a 
column labelled school which holds an enum data type comprised of the values 1 through 
40. From the website front end, where the data is being entered, i want to display, 
ideally a series of checkboxes, otherwise a list which would allow a user to select 
multiple items in that will translate into this enum field. For instance, a series of 
checkboxes with items such as abjuration, conjuration, divination, and others, which 
will all have a numeric value which gets plugged into the enum field. for instance, if 
a user selected abjuration, and divination, it would be plugged into sql as 1, 3 (or 
however enum data is input into its column). That being the case how do i utilize php 
to get this to work? what kind of form elements etc... The problem im seeing with 
checkboxes are that they are discreet and dont group together, so i cant get all the 
data to go into one column in mysql. Hopefully i havent horribly confused the issue 
and some kind soul out there can tell me how to send this data across. As a double 
nice thing...how would you write it to pull the data back out...ie, convert 1, 3 to 
show abjuration, divination? Thanks for the help in advance. 



Re[2]: [PHP] Enum table entry

2002-10-19 Thread Tom Rogers
Hi,

Saturday, October 19, 2002, 5:15:41 PM, you wrote:
JN You know, I didn't even think about serializing the array.  I have a 
JN table set up for spells, one for schools, and a linking table using the 
JN spell id and the school id(s).  I could have done without the linking 
JN table.  Some of you people are pretty freakin' smart. :)

JN One note though, when you pull the serialized data out, you may have to 
JN stripslashes before unserialize...

JN $school = unserialize ( stripslashes ( $row['school'] ) );

JN Tom Rogers wrote:
 Hi,
 
 Saturday, October 19, 2002, 2:48:14 PM, you wrote:
 SM Have a question that im trying to figure out how to resolve. I have a field 
type in mysql that is of the enum type. Unless youre familiar with Dungeons and 
Dragons, you wont get what the values
 SM mean, but hopefully youll get the gist anyway. I have a column labelled school 
which holds an enum data type comprised of the values 1 through 40. From the website 
front end, where the data is
 SM being entered, i want to display, ideally a series of checkboxes, otherwise a 
list which would allow a user to select multiple items in that will translate into 
this enum field. For instance, a
 SM series of checkboxes with items such as abjuration, conjuration, divination, 
and others, which will all have a numeric value which gets plugged into the enum 
field. for instance, if a user
 SM selected abjuration, and divination, it would be plugged into sql as 1, 3 (or 
however enum data is input into its column). That being the case how do i utilize php 
to get this to work? what
 kind
 SM of form elements etc... The problem im seeing with checkboxes are that they are 
discreet and dont group together, so i cant get all the data to go into one column in 
mysql. Hopefully i havent
 SM horribly confused the issue and some kind soul out there can tell me how to 
send this data across. As a double nice thing...how would you write it to pull the 
data back out...ie, convert 1, 3
 to
 SM show abjuration, divination? Thanks for the help in advance. 
 
  I have never used enum type but I am sure it is not what you want as
  it will only store one item from a predefined list not a list of
  items. What you need to do is create an array of the selected items,
  serialize() it to store in the database in a varchar or mediumtext if
  it going to get big. Then when you read it back unserialize and loop
  through all the options setting checked if it is in the array.
  To keep the checkboxes grouped name them like this:
  input type=checkbox name=school[1]
  input type=checkbox name=school[2]
  input type=checkbox name=school[3]
 
  That will show up as an array under $_POST['school']
  so you can serialize it as is and store it.
 
  ?
  if(isset($_POST['school'])) $school = serialize($_POST['school']);
  ?
 
  Playback is simple too
 
   ?
   $school = unserialize($row['school']);
   for($i = 1;$i  41;$i++){
  echo 'input type=checkbox name=school['.$i.']';
  if(isset($school[$i])) echo ' checked';
  echo '';
   }
 
   Un-checked boxes are not returned in the post and checked ones
   return Yes I think.
 
 
 

As the only thing going in is 1-yes add and strip isn't needed. You
should never need to stripslashes on db output under normal
conditions. If the data could contain single quotes and stuff then you would do it like
this

addslashes(serialize($_POST['school']));

-- 
regards,
Tom


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




[PHP] Re: [PHP-DB] Enum table entry

2002-10-19 Thread Rick Widmer
At 11:48 PM 10/18/02 -0500, Shiloh Madsen wrote:



 For instance, a series of checkboxes with items such as abjuration, 
conjuration, divination, and others, which will all have a numeric value 
which gets plugged into the enum field. for instance, if a user selected 
abjuration, and divination, it would be plugged into sql as 1, 3

Assuming your field is:

school enum( 'abjuration', 'conjuration', 'divination', ... ),

The database will return, 'abjuration,divination' in the example listed
above, and it will expect the same kind of string when setting the field
in an UPDATE or INSERT query.



(or however enum data is input into its column). That being the case how 
do i utilize php to get this to work? what kind of form elements etc... 
The problem im seeing with checkboxes are that they are discreet and dont 
group together, so i cant get all the data to go into one column in mysql. 
Hopefully i havent horribly confused the issue and some kind soul out 
there can tell me how to send this data across. As a double nice 
thing...how would you write it to pull the data back out...ie, convert 1, 
3 to show abjuration, divination? Thanks for the help in advance.



To get the data in/out of the database you can do something like this:


Start with an array of possible choices, because you are going to
have to act on each possible choice.

$SchoolChoices = array( 'Abjuration', 'Conjuration', 'Divination', ... );




To setup the variables from the table for display.  Note the value
from the database is in the string $School.


reset( $SchoolChoices );

while( list( , $Choice ) = each( $SchoolChoices )) {
   $VarName = 'School' . $Choice;
   $$VarName = ereg( $Choice, $School ) ? 'CHECKED' : '';
   }



Now you can send the form displayed below with the values from
the database.



FORM Method=GET  ...

INPUT Type=checkbox Name=SchoolAbjuration Value=?=$SchoolAbjuration?
INPUT Type=checkbox Name=SchoolConjuration Value=?=$SchoolConjuration?
INPUT Type=checkbox Name=SchoolDivination Value=?=$SchoolDivination?
...
/FORM

===


After the user enters the form, you can decode the fields and put the
data into a string for storage in the database with:


reset( $SchoolChoices );

$School = '';
while( list( , $Choice ) = each( $SchoolChoices )) {
   if( 'on' == $_get( School$Choice ))  {
  $School .= ',' . $Choice;
  }
   }

$School = substr( $School, 1 );


Now you can INSERT/UPDATE the database with $School to set the enum field.




You can create the checkbox fields from $SchoolChoices with the following:

reset( $SchoolChoices );

while( list( , $Choice ) = each( $SchoolChoices )) {
   $VarName = 'School' . $Choice;
   echo INPUT Type=\checkbox\ Name=\$VarName\ Value=\$$VarName\;
   }




For extra credit, figure out how you can create the $SchoolChoices array
from the output of the following query:

   DESCRIBE TableName School;

(Yes you can send this to mysql_query, and get the possible values of the 
enum.)



Rick  


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



RE: [PHP] Enum table entry

2002-10-19 Thread John W. Holmes
There should really be another table for all of this information. Say
you're tracking school information for a specific person. That person
would have an ID number and you'd store the school information in a
separate table that stores the user's ID and the school ID. You could
even expand this to track other items by adding a third column that says
the item being tracked is a school, spell, item, etc. This may seem like
a pain now, but it's going to be the most scalable solution. Using
serialize, what happens when someone has all 40 schools and it's over
255 characters? Do you make them all text columns?

An ideal solution would involve a variety of tables. Table 1: Users.
This would store user information such as name, rank, etc, and assign
each one a unique ID. Table 2: Schools. This would list all of the
possible schools that someone can take and assign each one a unique ID.
Table 3: Spells. This would list all of the possible spells and assign
each one a unique ID. Table 4: Call it what you want but this table is
going to link the user IDs to school and magic IDs. If a user
(User_ID=1) has schools abjuration (ID=2) and conjuration (ID=5), then
you'd have two rows in this linking table, 1-2 and 1-5. 

Okay... I've blabbered enough.

---John Holmes...

 -Original Message-
 From: Shiloh Madsen [mailto:shiloh_madsen;nsc-support.com]
 Sent: Saturday, October 19, 2002 12:48 AM
 To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: [PHP] Enum table entry
 
 Have a question that im trying to figure out how to resolve. I have a
 field type in mysql that is of the enum type. Unless youre familiar
with
 Dungeons and Dragons, you wont get what the values mean, but hopefully
 youll get the gist anyway. I have a column labelled school which holds
an
 enum data type comprised of the values 1 through 40. From the website
 front end, where the data is being entered, i want to display, ideally
a
 series of checkboxes, otherwise a list which would allow a user to
select
 multiple items in that will translate into this enum field. For
instance,
 a series of checkboxes with items such as abjuration, conjuration,
 divination, and others, which will all have a numeric value which gets
 plugged into the enum field. for instance, if a user selected
abjuration,
 and divination, it would be plugged into sql as 1, 3 (or however enum
data
 is input into its column). That being the case how do i utilize php to
get
 this to work? what kind of form elements etc... The problem im seeing
with
 checkboxes are that they are discreet and dont group together, so i
cant
 get all the data to go into one column in mysql. Hopefully i havent
 horribly confused the issue and some kind soul out there can tell me
how
 to send this data across. As a double nice thing...how would you write
it
 to pull the data back out...ie, convert 1, 3 to show abjuration,
 divination? Thanks for the help in advance.



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




[PHP] MySQL Insert Select statement

2002-10-19 Thread dwalker



Whilereading the MySQL manual for INSERT SELECT, I was 
not able to determine how to includeall 5 fields of one table into another 
table (containing 100 fields) into SPECIFIC data fields. Do I need to 
explicitly list all the fields within the table of 5 fields? If so, would 
the statement be:

INSERT INTO Products 
(ProductName,Size,SuggestedRetailPrice,ProductCategory,ManufacturerName)
SELECT(kalproduct.Product, kalproduct.size, 
kalproduct.SRP, kalproduct.Cat, kalproduct.manname)
FROM kalproduct 
;



Thanking you in advance.

P.S. I'd give it a try, but I'm trying to move 500 
partial records into a table containing at least 2000 records -- didn't want to 
start from scratch.










This email message and all attachments transmitted herewith 
are tradesecret and/or confidential information intended only for 
theviewing and use of addressee. If the reader of this 
messageis not the intended recipient, you are hereby notified that 
any review, use, communication, dissemination, distribution or copying 
of this communication is prohibited. If you have received this 
communication is error, please notify the sender immediately by telephone or 
electronic mail, and delete this message and all copies and backups 
thereof. 

Thank you for your cooperation.
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] RE: [PHP-DB] MySQL Insert Select statement

2002-10-19 Thread John W. Holmes
That's how you do it. Hopefully you've figured it out already. 

 

---John Holmes.

 

-Original Message-
From: dwalker [mailto:dwalker;healthyproductsplus.com] 
Sent: Saturday, October 19, 2002 7:51 PM
To: professional php; [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [PHP-DB] MySQL Insert Select statement

 

While reading the MySQL manual for INSERT SELECT, I was not able to
determine how to include all 5 fields of one table into another table
(containing 100 fields) into SPECIFIC data fields.  Do I need to
explicitly list all the fields within the table of 5 fields?  If so,
would the statement be:

 

INSERT INTO Products
(ProductName,Size,SuggestedRetailPrice,ProductCategory,ManufacturerName)

SELECT(kalproduct.Product, kalproduct.size, kalproduct.SRP,
kalproduct.Cat, kalproduct.manname)

FROM kalproduct 

;

 

 

 

Thanking you in advance.

 

P.S.  I'd give it a try, but I'm trying to move 500 partial records into
a table containing at least 2000 records -- didn't want to start from
scratch.

 

 

 

 

 

 

 

 

 

 

This email message and all attachments transmitted herewith are trade
secret and/or confidential information intended only for the
 viewing and use of addressee.  If the reader of this message
 is not the intended recipient, you are hereby notified that 
any review, use, communication, dissemination, distribution 
or copying of this communication is prohibited.  If you have 
received this communication is error, please notify the sender 
immediately by telephone or electronic mail, and delete this 
message and all copies and backups thereof.  

 

Thank you for your cooperation.




[PHP] Re: [PHP-DB] MySQL Insert Select statement

2002-10-19 Thread dwalker
For some reason the Insert Select statement returned an ERROR and I had to
resort to

INSERT INTO Products
(ProductName,Size,SuggestedRetailPrice,ProductCategory,ManufacturerName)

SELECT *

FROM kalproduct ;

Is there a noticeable reason why:

INSERT INTO Products
(ProductName,Size,SuggestedRetailPrice,ProductCategory,ManufacturerName)

SELECT(kalproduct.Product, kalproduct.size, kalproduct.SRP,
kalproduct.Cat, kalproduct.manname)

FROM kalproduct ;

would have returned an error message??  I don't want to have to create
multiple tables for the purpose of inserting into others.

-Original Message-
From: John W. Holmes [EMAIL PROTECTED]
To: 'dwalker' [EMAIL PROTECTED]; 'professional php'
[EMAIL PROTECTED]; [EMAIL PROTECTED] [EMAIL PROTECTED];
[EMAIL PROTECTED] [EMAIL PROTECTED]
Date: Saturday, October 19, 2002 7:24 PM
Subject: RE: [PHP-DB] MySQL Insert Select statement


That's how you do it. Hopefully you've figured it out already.



---John Holmes.



-Original Message-
From: dwalker [mailto:dwalker;healthyproductsplus.com]
Sent: Saturday, October 19, 2002 7:51 PM
To: professional php; [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [PHP-DB] MySQL Insert Select statement



While reading the MySQL manual for INSERT SELECT, I was not able to
determine how to include all 5 fields of one table into another table
(containing 100 fields) into SPECIFIC data fields.  Do I need to
explicitly list all the fields within the table of 5 fields?  If so,
would the statement be:



INSERT INTO Products
(ProductName,Size,SuggestedRetailPrice,ProductCategory,ManufacturerName)

SELECT(kalproduct.Product, kalproduct.size, kalproduct.SRP,
kalproduct.Cat, kalproduct.manname)

FROM kalproduct

;







Thanking you in advance.



P.S.  I'd give it a try, but I'm trying to move 500 partial records into
a table containing at least 2000 records -- didn't want to start from
scratch.





















This email message and all attachments transmitted herewith are trade
secret and/or confidential information intended only for the
 viewing and use of addressee.  If the reader of this message
 is not the intended recipient, you are hereby notified that
any review, use, communication, dissemination, distribution
or copying of this communication is prohibited.  If you have
received this communication is error, please notify the sender
immediately by telephone or electronic mail, and delete this
message and all copies and backups thereof.



Thank you for your cooperation.




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


[PHP] Re: [PHP-DB] MySQL Insert Select statement

2002-10-19 Thread Jeffrey_N_Dyke

what was the error?



   
  
dwalker  
  
dwalker@healthyproduct   To: [EMAIL PROTECTED], 
'professional php'   
splus.com [EMAIL PROTECTED], 
[EMAIL PROTECTED],   
   [EMAIL PROTECTED] 
  
10/19/2002 08:32 PM   cc:  
  
Please respond to Subject: Re: [PHP-DB] MySQL 
Insert Select statement
dwalker  
  
   
  
   
  




For some reason the Insert Select statement returned an ERROR and I had to
resort to

INSERT INTO Products
(ProductName,Size,SuggestedRetailPrice,ProductCategory,ManufacturerName)

SELECT *

FROM kalproduct ;

Is there a noticeable reason why:

INSERT INTO Products
(ProductName,Size,SuggestedRetailPrice,ProductCategory,ManufacturerName)

SELECT(kalproduct.Product, kalproduct.size, kalproduct.SRP,
kalproduct.Cat, kalproduct.manname)

FROM kalproduct ;

would have returned an error message??  I don't want to have to create
multiple tables for the purpose of inserting into others.

-Original Message-
From: John W. Holmes [EMAIL PROTECTED]
To: 'dwalker' [EMAIL PROTECTED]; 'professional php'
[EMAIL PROTECTED]; [EMAIL PROTECTED] [EMAIL PROTECTED];
[EMAIL PROTECTED] [EMAIL PROTECTED]
Date: Saturday, October 19, 2002 7:24 PM
Subject: RE: [PHP-DB] MySQL Insert Select statement


That's how you do it. Hopefully you've figured it out already.



---John Holmes.



-Original Message-
From: dwalker [mailto:dwalker;healthyproductsplus.com]
Sent: Saturday, October 19, 2002 7:51 PM
To: professional php; [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [PHP-DB] MySQL Insert Select statement



While reading the MySQL manual for INSERT SELECT, I was not able to
determine how to include all 5 fields of one table into another table
(containing 100 fields) into SPECIFIC data fields.  Do I need to
explicitly list all the fields within the table of 5 fields?  If so,
would the statement be:



INSERT INTO Products
(ProductName,Size,SuggestedRetailPrice,ProductCategory,ManufacturerName)

SELECT(kalproduct.Product, kalproduct.size, kalproduct.SRP,
kalproduct.Cat, kalproduct.manname)

FROM kalproduct

;







Thanking you in advance.



P.S.  I'd give it a try, but I'm trying to move 500 partial records into
a table containing at least 2000 records -- didn't want to start from
scratch.





















This email message and all attachments transmitted herewith are trade
secret and/or confidential information intended only for the
 viewing and use of addressee.  If the reader of this message
 is not the intended recipient, you are hereby notified that
any review, use, communication, dissemination, distribution
or copying of this communication is prohibited.  If you have
received this communication is error, please notify the sender
immediately by telephone or electronic mail, and delete this
message and all copies and backups thereof.



Thank you for your cooperation.




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




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