Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Inserting multi into mapping table

  • 05-02-2009 11:55am
    #1
    Closed Accounts Posts: 73 ✭✭


    HI again

    Can anyone tell me how to insert the multi selection form a list menu into a mapping table.

    I think i need to use a loop but which loop and how to write it. well that is why i'm here.

    Please help


Comments

  • Registered Users, Registered Users 2 Posts: 197 ✭✭cracker


    I have never done any PHP but based on how I would do it with other languages I would use a foreach loop. From googling i got this syntax for PHP

    foreach (array as value)
    {
    code to be executed;
    }

    so you would need to get your list menu items returned as an array, is there a method on the list menu object that returns an array of items?
    If so then something like this

    foreach (myListMenu.getItems() as value)
    {
    //each iteration of the loop will give you the next item
    //so something like
    myVal = value.getItemValue()
    do you insert sql statement using myVal
    }


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Protype wrote: »
    HI again

    Can anyone tell me how to insert the multi selection form a list menu into a mapping table.

    I think i need to use a loop but which loop and how to write it. well that is why i'm here.

    Please help

    I gave you a good start on this in one of your other threads.

    If you select more than one value from a dropdown list, the values will appear in one string, separated by commas.

    Therefore you must split the string into an array, using the comma as the delimiting character. When you loop through this array, you will then be able to get each value on its own, and at that stage you execute an insert statement against the database.

    Check out this page.
    http://www.webhostingtalk.com/showthread.php?t=700871


  • Closed Accounts Posts: 73 ✭✭Protype


    is this what i want
    [HTML]
    [Instructor_Qual_id] => Array
    (
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    )
    [/HTML]

    I don't know if what im getting is what i need


  • Closed Accounts Posts: 73 ✭✭Protype


    WHAT DO I DO WITH THIS AS I AM STUMPED.
    I have read all info i could find but i just don't know

    This is the insert for the form field where i need the multi selection to go to the database. Even if you could tell me to put the loop it would help

    [PHP]

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "DI_Update")) {
    $insertSQL = sprintf("INSERT INTO instructor_qualmaster_info (Instructor_Qual_id, master_id) VALUES (%s, last_insert_id())",
    GetSQLValueString($_POST, "int"));

    mysql_select_db($database_DI_Directory, $DI_Directory);
    $Result1 = mysql_query($insertSQL, $DI_Directory) or die(mysql_error());
    }

    [/PHP]


  • Registered Users, Registered Users 2 Posts: 197 ✭✭cracker


    i am not familiar enought with PHP to know how you get your items into an array but once you have it you need to put the foreach inside the IF and around everything else (I assume you are only doing the insert when the IF condition is met). Then replace in your $insertSQL with the variable in your foreach statement ('value' in the example I have below) so you end up with something like.


    foreach (array as value){
    $insertSQL = sprintf("INSERT INTO instructor_qualmaster_info (Instructor_Qual_id, master_id) VALUES (%s, last_insert_id())",
    GetSQLValueString($_POSTCOLOR="Red"]value[/COLOR,"int"));

    mysql_select_db($database_DI_Directory, $DI_Directory);
    $Result1 = mysql_query($insertSQL, $DI_Directory) or die(mysql_error());
    }


  • Advertisement
  • Closed Accounts Posts: 73 ✭✭Protype


    What is wrong with this code, "cos it is sending" just not sending all selections.

    [PHP]if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "DI_Update")) {
    $Quals = explode(", ",$_POST, 50); // what is this (50) for
    if (!(isset($quals[7]))) { // assign each element in the Quals array to the temp varibale
    foreach ($Quals as $Quals_value) {
    $Quals_value = trim($Quals_value);
    $insertSQL = sprintf("INSERT INTO instructor_qualmaster_info (Instructor_Qual_id, master_id) VALUES (%s, last_insert_id())",
    GetSQLValueString($Quals_value, "int"));

    mysql_select_db($database_DI_Directory, $DI_Directory);
    $Result1 = mysql_query($insertSQL, $DI_Directory) or die(mysql_error());
    }
    }
    }[/PHP]


Advertisement