This topic is locked

multiselect+listbox+one-to-many

2/29/2008 8:44:27 AM
PHPRunner General questions
F
Fanta author

Hy everybody!
I have a little bit a problem with multiselect and listbox.
For example, let's say I have three tables: Company, Products and Company-Products
Company table contains lists of firms
Products table contains lists of produts
I want to put in Company_Products table list of all products that some company have.
So I open some company, let's call her FIRM, and in listbox I open list of all products such as apple, banana, orange, strawberry, kiwi, ...
I use multiselect listbox to select some fruits from listbox such as (apple, banana, kiwi). When I stored them in the table Company_Products I got this kind of result:
FIRM apple, banana, kiwi
That is not kind of resultat I want, because i one to have relationship one to many, meaning, I one to store like this
FIRM apple

FIRM banana

FIRM kiwi
Is that possible in PHPRunner????

J
Jane 3/3/2008

Hi,
you can parse entered value and insert separate record to the table manually in the Before record added/Before record updated events on the Events tab.

Here is a sample:

global $conn;

if ($values[FieldName"])

{

$arr = explode(",",$values["FieldName"]);

for ($i=0;$i<count($arr);$i++)

{

$strInsert = "insert into TableName (FieldName,FieldName2) values ('".$arr[0]."','".$values["FieldName2"]."')";

db_exec($strInsert,$conn);

}

}

F
Fanta author 3/3/2008

Hi,

you can parse entered value and insert separate record to the table manually in the Before record added/Before record updated events on the Events tab.

Here is a sample:


Thank you very much Jane for help, I will try it tomorrow. If I have any problem again, I will post it here.

F
Fanta author 3/4/2008

I have to change a little bit your cod only in one line:
Instead of:
$strInsert = "insert into TableName (FieldName,FieldName2) values ('".$arr[0]."','".$values["FieldName2"]."')";
it should be:
$strInsert = "insert into TableName (FieldName,FieldName2) values ('".$arr[$i]."','".$values["FieldName2"]."')";
Now my code works fine, but I still have one more problems:
even if he now separate fields and it stores them separately it still save in one of the line all records together.
So the values in my table now looks like:
FIRM apple, banana, kiwi

FIRM apple

FIRM banana

FIRM kiwi
How to stop him to store in the field where are all records together, just to leave those which are separately???

J
Jane 3/5/2008

Hi,
just replace > return true;

with > return false;

in your event.

F
Fanta author 3/5/2008

Thank you Jane, this part of my program now works perfect. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=26649&image=1&table=forumreplies' class='bbc_emoticon' alt=':lol:' />
Now I just to try to found the way how to put values from one listbox to another with javascript (another listbox is made by me) and I need to took values from that second listbox, and put them in database. If I stumble somewhere again, I will be back to you.

F
Fanta author 3/5/2008

I just remember one more problem.
The dropdown is displaying values from one of the columns in my table. Some values are long and some are short.
My problem is that the dropdown lisbox is wide as the longest values from my column in my table, and after that it looks like that my dropdown listbox is wide as 17" monitor.
Is there any way to say for {build_edit_control field} that I want to him be wide as 512 px. You now what i mean, for example width="512px".

J
Jane 3/5/2008

Hi,
you can change dropdown box width in the BuildSelectControl function in the generated include/commonfunctions.php file only.

F
Fanta author 3/18/2008

I tried to add style="WIDTH: 512px" but nothing is changing. In which line of code of the BuildSelectControl function should I add that code???
Or did I forgot something???