vincevincevince

msg:4519211 | 1:29 am on Nov 15, 2012 (gmt 0) |
$_POST['multi'] will already be an array; if you want to separate them by commas, implode: implode(",",$_POST['multi']); However: if this is a public facing system, then please do some careful checks on valid values... I do it like this:
$data=Array(); foreach ($_POST['multi'] as $k=>$v) if (intval($k)) $data[]=intval($k); $sql="INSERT .......".implode(",",$data)";
That way, only data which is a positive integer will be inserted.
|
whatson

msg:4519273 | 7:14 am on Nov 15, 2012 (gmt 0) |
And it would be best in the database like 1,2,3, etc.. with the commas? would that be the easiest way to manage them?
|
swa66

msg:4519366 | 2:19 pm on Nov 15, 2012 (gmt 0) |
As for the datamodel I''m by far not convinced imploding into one field is a smart choice. It seems to me you have a 1:N relation, and should model it appropriately to normalize your data and as such maximise the use of what your relational database can offer.
|
vincevincevince

msg:4519372 | 2:38 pm on Nov 15, 2012 (gmt 0) |
It really depends on what you want to do with the data later. Comma separated strings are not convenient or efficient for searching by, but if it's just retrieval and you'll always want to retrieve the full set - then yes, do use comma separated strings. Otherwise, what swa66 said.
|
whatson

msg:4519450 | 6:58 pm on Nov 15, 2012 (gmt 0) |
It's for tags, I want to be able to tag categories for a page.
|
swa66

msg:4519523 | 12:13 am on Nov 16, 2012 (gmt 0) |
Sounds like an N:N relation even. What I'd model are 3 tables: e.g. Widgets - widgetId - widgetName - ... These essentially descibe a widget for each row, leaving out all info about tags Tags - tagID - tagName - ... These essentially define a tag without thinking to what widget they apply WidgetTag - widgetId - tagId These link the tags and widgets together. A tag can be used on multiple widgets and a widget can have multiple tags. That way a query to find all widgets with a given tag can be made, a query to know all possible tags, en query to find what tags a widget has are all eauqlly easy (just a couple of joins in one select statement)
|
|