EDIT/UPDATE 逗号分隔值到 mysql 行并添加新的

EDIT/UPDATE comma separated values into mysql rows and add new

EDIT/UPDATE 逗号分隔值到行并添加新的

我正在尝试编辑不同行中带有 ajax 的产品,然后从中更新并添加新行 使用相同名称创建动态字段的表单[]

但不知道如何拉动它们进行编辑然后在同一位置更新它们,因为它们位于我需要更新的不同行和表中

我能想到的编辑它们的唯一方法就是这个例子 http://www.infotuts.com/ajax-table-add-edit-delete-rows-dynamically-jquery-php/ 但这是对每一行使用 1 行,我有不同行的产品

不知道是否应该像这样实时编辑它们,但我将如何提取旧行并添加新行以及链接到同一订单 http://www.aquim.com/web-article-229.html

我试图编辑它们然后更新它们,但是我如何更新旧产品以及添加新产品并将它们链接到不同的表

编辑表格

产品 1 [产品 1 行] [价格 1] [数量 1] [总数 1]

产品 2 [产品 2 行] [价格 2] [数量 2] [总数 2]

然后用表格添加新产品

<pre>`
  <form name="test" method="post" action="">
    <div id="container">
    <p id="add_field"><a href="#"><span>&raquo; Add New Bid</span>    </a></p>
    </div>
  </form>
 $('p#add_field').click(function(){
    count += 1;
    $('#container').append(
        '<strong>Link #' + count + '</strong><br />' 
        + '<input id="field_' + count + '" name="fields[]' + '" type="text" placeholder="Product Name" /><br />' 
        + '<input id="field_' + count + '" name="price[]' + '" type="text"  placeholder="Price"/><br />' 

        );

   });`

SELECT 旧产品和更新,然后获取 ID 并添加新产品,然后 LINK 到 TABLE

我考虑过的唯一可能进行更新的方法是擦除所有内容并重新插入它,但我认为如果多人这样做,将来会导致冲突

             quotes TABLE 1

|报价编号 | bid_name |状态 |总计 |

|----------------------------|

| 1 |出价1 |待定 | 100 |

| 2 |出价2 | stuff_y | 200 |

              quote_products_link TABLE 2

|报价编号 |产品编号 |
|----------------------------|

| 1 | 4 |

| 1 | 4 |

| 2 | 5 |

| 2 | 5 |

              quote_products_link TABLE 3

|产品编号 | product_name |价格 |数量 | bid_name |

| 4 | pro_1 | price_1 | quan_1 | bid_1 |

| 4 | pro_2 | price_2 | quan_2 | bid_1 |

| 5 | pro_3 | price_3 | quan_3 | bid_2 |

| 5 | pro_4 | price_4 | quan_4 | bid_2 |

你可以拉---检查---更新---删除

伪代码,无效!这是为了展示流程:

// Get the current database rows that are being edited
$results = mysql_query('SELECT * FROM entries WHERE table_id=10');
$itemsInDB = [];
while($itemsInDB[] = mysql_fetch_row($results)) {}

// Iterate over the fields sent to the server
foreach($_POST['fields'] as $index=>$value) {
    // New Values that were submitted
    $field = $value;
    $price = $_POST['prices'][$index];

    // Get Rid Of Updated Rows From Pulled Array
    $found = false;
    foreach($itemsInDB as $dbindex=>$dbvalue) {
       // Check if the row exists in the database
       if ($dbvalue['field'] == $field) {
           $found = true;

           // Update the values that have changed
           if ($price !== $dbvalue['price'])
               UpdateDatabase('SET price=$price WHERE field=$field');

           // Remove the row from the pulled database rows
           array_shift($itemsInDB($dbindex,1);
       }
    }

    // insert it because it wasnt in the database
    if (!$found) 
       InsertDatabase('Values($field,$price)');
}

// Now that you have updated all the rows that were submitted
// The rows that are in the database that were not updated
// Need to be deleted because the user has removed them from the table
foreach($itemsInDB as $row) {
    $field = $row['field'];
    DeleteDatabaseRow('WHERE field='.$field.' LIMIT 1');
}

可能有更好的方法来做到这一点......我前段时间遇到这个问题时就是这样做的。

拉产品

$sqlString = "SELECT  
 GROUP_CONCAT(productID) AS id,
GROUP_CONCAT(productName) AS productsname,
GROUP_CONCAT(price) AS prices,
bidid FROM products GROUP BY bidid";

while($row = $result->fetch_array(MYSQLI_ASSOC)){
   $currentbid[$row['bidid']][] = $row;  

}

foreach ($currentbid as $bid => $itemList){

   foreach($itemList as $itemInfo => $loas){

 // count ids, by create a rande array or counting the wors
foreach(explode(",",$loas['id']) as $itemInfoss){

then inside the foreach - create the table rows

   $str.='<tr id="'.$itemInfoss.'" 

更新它们 取决于你如何更新它们 我正在使用序列化函数和一些自定义数据更新它们

为了获取 ID,我使用 javascript 将它们推送到一个数组中

  mysqlrow.push($js(this).attr('data-rowid'));

先删除它们

   if(!empty($deleteoldproductsfrom)){

                foreach($erasecount as $deleteold){

                 $deleteProducts = "DELETE FROM products WHERE 

productID='$deleteold' ";

然后更新

    $sql_quote_add = "SELECT * FROM quotes WHERE bid_name ='$quotename' "; 

    $client_data = $con->query($sql_quote_add); 

获取 ID 以查看它是否与提交的任何 ID 匹配

   $getquoteid= mysqli_fetch_assoc($client_data);   

    $oldquoteid = $getquoteid['quoteID']; 

// 这取决于您提交的方式,我正在提交 ajax 对于 ( $for =0; $for < count($data['productName']); $for++) {
然后在 for lopp 里面 我们检查 ID 是否匹配任何当前产品

我分解了一个我提交的数组,这是我想到的最简单的方法,然后在里面做一个计数,这样它就可以循环

 if($tagArray[$for] == $pro_old_id){

    $updateold = "UPDATE products SET price='$priceNew', 

   } else
 $sql_bid = sprintf("INSERT INTO products

 }