If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Concatinate insert into MYSQL DB

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-01-10, 11:08
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Concatinate insert into MYSQL DB

Goal: Have a dynamic list to check boxes which will be inserted into one field in the DB coma separates!

For example; I have check boxes for red(1), green(2), blue(3) and yellow(4). I want the client to select as many as they wish and insert the numbers into one field in the DB. So the field colors might have a value of 1,3,4.

Any ideas

Nick
Reply With Quote
  #2 (permalink)  
Old 11-01-10, 11:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
Quote:
Originally Posted by oldnickj View Post
...which will be inserted into one field in the DB coma separates!
that's a bad idea -- it will put your query performance into a coma

Quote:
Originally Posted by oldnickj View Post
... and insert the numbers into one field in the DB.
Code:
INSERT
  INTO daTable
     ( somekey
     , colors )
VALUES
     ( 'somevalue'
     , '1,3,4' )
it's still a bad idea, but that's how you do it
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-01-10, 11:34
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
This is going to be a large table of image file names and I want to include attributes, like colors, but the list is quite long and rather then have a wide table, which I have to constantly alter, I thought I would store the attributes in one simple field then when I want images with several attributes I query on LIKE IN().

What's bad?
Hi by the way.

Nick
Reply With Quote
  #4 (permalink)  
Old 11-01-10, 11:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
Quote:
Originally Posted by oldnickj View Post
What's bad?
the SQL to find all red images will be forced to use a table scan

the SQL to display all colour names for each image will be practically impossible to write -- try it yourself first before you commit to the comma-delimited design
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-01-10, 12:01
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
The list is finite, from a lookup (label) table which is populated by a client form. I would like to store just the key from 'label'.
Reply With Quote
  #6 (permalink)  
Old 11-01-10, 12:07
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Create three tables, pictures, attributes, and picture_attributes. In the pictures table, include all of the information about a picture (size, format, URL or UNC, etc). In the attributes table, have one row for each attribute (red, large, pastel, landscape, etc). In the picture_attributes table, have one row for each attribute that a picture has: Picture one might have rows for landscape and JPEG and picture 937 might have rows for pastel and GIF.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #7 (permalink)  
Old 11-04-10, 10:28
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Implode

the solution which gave me the desired result was to rename the check boxes and customize the insert value.

The field name had to be renamed to: from theme to theme[] to create the array.

the insert had to be customied form:
<?php echo((isset($_POST["theme_img[]"]))?$_POST["theme_img[]"]:"") ?>

to
<?php echo(isset($_POST['theme_img[]'])?implode(", ", $_POST['theme_img[]']):""); ?>

the next task is to figure out how to populate the correct check boxes on the update page!

I'll be back.

Nick
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On