Page 1 of 1

columns in mysql-

Posted: Wed Aug 27, 2003 5:36 pm
by Amy1
As you can see from the following questions -I am quite new to mysql!!

1)How can I set up a column with pre-defined values so that I can use them in check boxes and/radio buttons or lists? How can I design my table so that it shows the check box, etc.?

2)Can I assign calculations to a column: ie: column c= column a + colunm b

3)How can I set a modification date column so that will insert the date automatically after any modification to the database?

4) I want to put a reference to image dir into a varchar column but I don't know the sytax for it do I just go like this: images/image.jpg or full address and do I use any quotation marks????

Thanks

Posted: Wed Aug 27, 2003 6:38 pm
by Stoker
you really should look for some introduction to database usage, and some db with php howtos...

1. Column types SET and ENUM can do such but normally you do not do that, you store byte or integer or char that represents it, as a foreign key from another table or and id of your own constants or array or similar..

2. You can do this with functions yes, UPDATE tablename SET columnc = columna + columnb but it really makes no sense and creates needless space usage, instead create that when you need it.. SELECT (columna+columnb) AS myvirtualcilumn

3. With mysql I believe the datatype timestamp will automatically update the column on any change to the record (not to the database or table).

4. What you store in the string to refer you to the files depends on your application.. if all images is in the images/ dir there is no point storing images/ with every record, just store whatever the path is from the root of all your images and make your app concatenate that after a fixed 'images/' when outputing it.. Not sure if I understood the ref to quotationmarks, as ALWAYS you need to escape any quotes and control chars from the string, preferably using mysql_escape_string($var).