满足下拉条件时为值添加“S”前缀

Posted

技术标签:

【中文标题】满足下拉条件时为值添加“S”前缀【英文标题】:Add "S" prefix to values when meeting dropdown condition 【发布时间】:2020-02-11 05:55:08 【问题描述】:

如果用户从下拉列表中选择“SH”,我希望在我的 $tranid 中添加“S”前缀(不带引号)。

所以会变成S$tranid,所以会变成S000001

我之前尝试过 concat,但似乎我搞砸了,它根本不起作用。

@这是我的 strsql 查询

/** Start To Save New record **/
if($action == "SAVE_DATA")
 
  if($tranid == "")
  
    $strSQL = "select cs.getInvNo('SH') as tranid; ";
    $result = mysql_query($strSQL) or die ("sql error in retrieving trans id.");
    if ($row = mysql_fetch_array($result))
    
      $tranid = $row['tranid'];
    
  


  $strSQL = "insert into cs.cs_inv_header(inv_no,inv_date,inv_so,inv_bill_to,inv_ship_to,inv_loc,";
  $strSQL .="inv_cust_code,inv_po,inv_term,inv_curr,inv_ship_via,inv_status,inv_cby,inv_cdate) ";
  $strSQL .= "values('$tranid','$shipDate','$so','$custNo','$shipTo','$loc','$custNo','$ref',";
  $strSQL .= "'$term','$curr','$shipVia','Y','".$_SESSION['SYS_CS']['USER_ID']."',now());";
  mysql_query($strSQL,$link) or die ("sql error on inserting cs.cs_inv_header.");
  unset ($strSQL);

  $strSQL = "insert into cs.cs_inv_det(invd_no,invd_part,invd_desc,invd_qty,invd_uom,invd_cost,";
  $strSQL .="invd_total,invd_vend_part,invd_rmk_ori,invd_rmk,invd_cby,invd_cdate) ";
  $strSQL .= "values('$tranid','$part','$desc',$qty,'$uom',$cost,$total,'$custPart','$rmk',";
  $strSQL .= "'".mysql_real_escape_string($rmk)."','".$_SESSION['SYS_CS']['USER_ID']."',now());";
  mysql_query($strSQL,$link) or die ("sql error on inserting cs.cs_inv_det.");
  unset ($strSQL);
  echo "<div class=std align=center>Invoice : $tranid Successfully created...</div>";
  $tranid = "";
  $so = "";
  $custNo = "";
  $term = "";
  $ref = "";
  $shipVia = "DDP";
  $curr = "";
  $part = "";
  $uom = "";
  $cost = "";
  $qty = "";
  $total = "";
  $desc = "";
  $rmk = "";
  $loc= "";

/** End of Saving new record **/

@这是我的下拉菜单代码

      <select name="selLoc">
       <option value = "">--Please Select--</option>
       <option value = "HB" <? if($loc=='HB') echo 'selected' ?>>HB-Thailand</option>
       <option value = "HH" <? if($loc=='HH') echo 'selected' ?>>HH-Thailand</option>
       <option value = "MH" <? if($loc=='MH') echo 'selected' ?>>MH-Malaysia</option>
       <option value = "SH" <? if($loc=='SH') echo 'selected' ?>>SH/option>
      </select></td>

【问题讨论】:

请注意,这种原始且不安全的 API 在十多年前已被弃用。 【参考方案1】:

你可以简单地在值行上这样做

$strSQL .="values('S$tranid','$part','$desc',$qty,'$uom',$cost,$total,'$custPart','$rmk',";

【讨论】:

以上是关于满足下拉条件时为值添加“S”前缀的主要内容,如果未能解决你的问题,请参考以下文章

Molly‘s Chemicals (前缀和+map用法,直接对应答案)

LeetCode周赛第三题——5765. 跳跃游戏 VII(dp+前缀和)

COM Interop的重命名/前缀类

[PKUSC2018]最大前缀和(DP)

[日常摸鱼]杜教筛

hihocoder1800