SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2005
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Working through an Array

    I have a simple array that comes from a form.

    it has a $load_id, $year_make_model_1,$VIN_number_1, $year_make_model_2,$VIN_number_2, $year_make_model_3,$VIN_number_3, $year_make_model_4,$VIN_number_4, $year_make_model_5,$VIN_number_5, $year_make_model_6,$VIN_number_6, $year_make_model_7,$VIN_number_7, $year_make_model_8,$VIN_number_8, $year_make_model_9,$VIN_number_9.



    So i am tring to insert the single load_id and put it in another table so I can search each load by VIN#. So it needs to insert like this for a single load:

    Load ID
    Year Make Model VIN #

    15434 Dodge Neon 1D4GP21EX6B515524
    15434 Dodge Magnum 1D4GP21E06B514575
    15434 ECT. Ect. ect. Ect

    keeps going until all the units are in the table.



    Year/Make/Model VIN
    Dodge Neon 1D4GP21EX6B515524
    Dodge Magnum 1D4GP21E06B514575
    Dodge Magnum 1D4GP21E66B514399
    Dodge Ram 1500 1D4GP21E66B514483
    Dodge Caravan 1D4GP21E46B561852
    Dodge Caravan 1D4GP21EX6B511814
    Dodge Caravan 1D4GP21E66B514581


    or it would be like taking a shoping cart and taking the items that are in your shoping cart and giving each item the same invoice or order id.

    Any way i hope a simpe foreach loop will work.










    $row =

  2. #2
    SitePoint Zealot Seriph's Avatar
    Join Date
    Oct 2005
    Location
    San Diego, CA
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hacked this together pretty quick - no testing, so, look it over, and check for mistakes.

    PHP Code:
    //Asuming the load_id column is an auto-inc field in its table which im calling "loads"

    $sql "INSERT INTO `loads` (`something`,`something2`) VALUES 
    ('whatever', 'whatever')"
    ;

    mysql_query($sql);

    $load_id mysql_insert_id();

    for (
    $i 1$i 9$i++) {
         eval(
    "\$sqlvals[] = (\$load_id, \$VIN_number_$i, \$year_make_model_$i)");
    }

    $sql2 "INSERT INTO `cars` (`load_id`,`vin`,`ymm`) VALUES ".join(','$sqlvals);

    mysql_query($sql2); 

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2005
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    //Asuming the load_id column is an auto-inc field in its table

    the "load" table is an auto_increment and the vin_search table is the where load_id is not an auto_incrment and you can put anything you want there. I created a form that holds orgin and destination fields with the # of units and that is where i get the load id in the first place. then i am trying to take load id and cars and vins and store them in the vin_search table. so you have to just take the load id and repeat it each time and loop through each units and still put that same load id with each different unit.

  4. #4
    SitePoint Zealot Seriph's Avatar
    Join Date
    Oct 2005
    Location
    San Diego, CA
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I'm interpreting what you mean correctly, then that is basically what this code does. The last part is the part that creates the SQL to insert the units with the same load_id. It inserts all of them at the same time, pulling the values from the $year_make_model_X, and $vin_number_X. It is set to use 9 as the limit in the for loop, which will go to $year_make_model_8.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •