I have been struggling with a design issue and I think I have come to the conclusion that you "can't do that with PHP/MySQL". Please help me confirm.
I have a site with 100+ products and would like to allow a salesperson to log in and be able to choose their region and then choose a set of products that they sell in that region from the entire product table, inserting their "set" (say 14 out of 125) into a row defined by their region/name/set.
I assumed for a while that I could load the whole product table of numbers/names into a select list form, have them choose their region/set and then have PHP insert that set (just ID numbers) into a field as a simple text list separated by spaces. Then I would be able to pull that field and use it as an array to then display their set in the future. HA.
First of all, I can't get the field to accept my insert record statement (it just puts the text "Array" in the field).
mysql_fetch_array only seems to work on multiple row query results. So, I may not be able to use that field even if it were populated.
Do I hear a round of "dohs"?
Any pointers would be appreciated. Other options for doing the same thing?
thanks
Arrays in single row/column?
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
If you had:
you would get as output:
If you show us the code you're having problems with then we will probably be able to help you out a bit more.
Mac
Code: Select all
$myarray = array('a', 'b', 'c');
echo $myarray;Code: Select all
ArrayMac
OK. Looking a bit further into my books I found the explode function which I think is the solution to getting the list of values and making use of them.
I'm still not sure how to get the values "In" to the column.
Here's the basic multiple select list I'm using:
Fairly basic
But, I can't seem to get the usual Insert function to accept the array created by the multiple-select as text string.
I guess I need to make a function to convert to a string from the array, then inser, yes?
I'm still not sure how to get the values "In" to the column.
Here's the basic multiple select list I'm using:
Code: Select all
<select name="prod_idї]" size="15" multiple id="prod_idї]">
<?php
do {
?>
<option value="<?php echo $row_rsProdsї'products_id']?>"><?php echo $row_rsProdsї'products_name']?></option>
<?php
} while ($row_rsProds = mysql_fetch_assoc($rsProds));
$rows = mysql_num_rows($rsProds);
if($rows > 0) {
mysql_data_seek($rsProds, 0);
$row_rsProds = mysql_fetch_assoc($rsProds);
}
?>
</select>But, I can't seem to get the usual Insert function to accept the array created by the multiple-select as text string.
I guess I need to make a function to convert to a string from the array, then inser, yes?
OK. I figured it out.
There are actually 3 ways to do it, once you get your array from the select-multiple.
join($array)/unjoin($array)
implode($array)/explode($array)
serialize($array)/unserialize($array)
Serialize seems to be the best as it has built-in capability for addslashes
then MySQL is quite happy storing the array in a column.
There are actually 3 ways to do it, once you get your array from the select-multiple.
join($array)/unjoin($array)
implode($array)/explode($array)
serialize($array)/unserialize($array)
Serialize seems to be the best as it has built-in capability for addslashes
then MySQL is quite happy storing the array in a column.