So to explain the problem.
I have a product table and an product application table,
The application table contains an ID, the name of the application. (and other stuff not relevant)
e.g.
table_application
ID Name
1 Disk Duplication
2 Disk Erasure
The product table, has an application field, which contains a serialised list of the application ID's
e.g.
Id Name APPL
1 Disk Doubler 1|2|5|9
now then to the problem....
I have an admin screen that shows a 'select multiple' combo box that lists the names of the applications, and highlights the ones that have been registered against the product.
to build the combo box, I retrieve all of the applications ID's and the APPL field for the product being edited.
Select ID, Name from product_application
Select APPL from products where ID =1
I convert the 'APPL' field into and array around the pipe:
I then build an options list by looping through the full list of application ID's and see if any of the values in the array I just made are found in the list.Code:$APPL = explode("|", $row[APPL]); I then have an array with the applications that the product is assigned to: [0]1, [1]2, [2]5, [3]9
When one is found (is_array=true), I can add the 'selected' option to the optionList so it appears as selected in the form..
I hope that's clear what I'm trying to do... simply see if the application ID in the array is in the returned list of possible application ID's and add the SELECTED flag. (easy right?Code://start the option list $optionList="<select multiple name='applicationSelect'>"; //get all the applications select * from table_application while $row(blahblah) { if (in_array($row[ID], $APPL)) { //product is marked as belonging to the application group //add SELECTED to the option, and append to variable $optionlist .="<option value='$row[ID]' SELECTED>$row[Name]</option>"; }else{ //just insert a regular option appended to variable $optionlist .="<option value='$row[ID]' >$row[Name]</option>"; } } //close the option $optionList .="</select>";)
The problem is - no matter what I do, the if statement:
if (in_array($row[ID], $APPL))
always returns false.
I think this has something to do with the two variable types being compared by 'in_array' not being the same.
I have tried setting $row[ID] to be a straight variable inside the while loop, and then using settype to make it an integer.. e.g.:
but this doesn't seem to work either...Code:$optionList="<select multiple name='applicationSelect'>"; select * from table_application while $row(blahblah) { $appIDROW=$row[ID]; $appIDROW=settype($appIDROW, 'Int'); if (in_array($appIDROW, $APPL)) { ..............
If I do this...
then this works fine....Code:select * from table_application while $row(blahblah) { $appIDROW=2; if (in_array($appIDROW, $APPL)) {
So this tells me it MUST have to with the variables not being the same type... right???
can anyone help?
cheers,
Mitch.



)


Bookmarks