我有一個函數,它允許我爲循環中的每個進程保存被刪除的對象。 Fiddle here我正在爲每個進程創建一個數組,並在其中存儲丟棄的物品。功能我用它來保存DROP掉的物品:打破數組中的數組php
<script>
var LISTOBJ = {
saveList: function() {
$(".leader").each(function() {
var listCSV = [];
$(this).find("li").each(function(){
listCSV.push($(this).text());
});
var values = listCSV.join(', ');
$(".output").append("<input type='hidden' name='leader[]' value='"+values+"' />");
$("#output").append("<p>"+values+"</p>");
console.debug(listCSV);
});
}
}
</script>
什麼打印保存的對象後,我得到:
Array ([0] => aaronjames,adelyn [1] => benny,bryanooi)
我想存儲在數據庫中的名稱和即時通訊能夠做到這一點,但它專賣店數組。所以我正在尋找一種方法來破壞數組內的數組,而不是存儲完整的數組。 我有2個表格:'project' and 'process'
。我正嘗試將名稱插入'process'
表中。我能夠這樣做。但它仍然是一個數組。 這裏是我用來在數據庫中存儲收到的值的函數。我生成的項目數量和使用foreach
爲每個進程分配名稱
function insertRecord(){
global $holdcode,$holdtitle,$projLeader,$projChecker,$holdremark,$holdprocess,$holdnumber,$procLeader,$procChecker, $prodStuff;
// To protect MySQL injection (more detail about MySQL injection)
$holdcode = cleanInputData($holdcode);
$holdtitle = cleanInputData($holdtitle);
$projLeader = cleanInputData($projLeader);
$projChecker = cleanInputData($projChecker);
$holdremark = cleanInputData($holdremark);
$holdcode = mysql_real_escape_string($holdcode);
$holdtitle = mysql_real_escape_string($holdtitle);
$projLeader = mysql_real_escape_string($projLeader);
$projChecker = mysql_real_escape_string($projChecker);
$holdremark = mysql_real_escape_string($holdremark);
$result = getLastProjectNo();
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if(mysql_num_rows($result) == 0)
{
$year = date("y");
$month = date("m");
$number = sprintf("%04d", 1);
$yearStr = strval($year);
$monthStr = strval($month);
$numberStr = strval($number);
$projectNo = $yearStr . $monthStr . $numberStr;
}
else{
if ($row_last = mysql_fetch_array($result))
{
$row_last[0] = cleanOutputData($row_last[0]);
$projectNo = $row_last[0];
$extractedNumberStr = substr($projectNo, -4);
$extractedYearMonthStr = substr($projectNo, 0, 4);
$year = date("y");
$month = date("m");
$yearStr = strval($year);
$monthStr = strval($month);
$currentYearMonthStr = $yearStr . $monthStr;
if($extractedYearMonthStr == $currentYearMonthStr)
{
$extractedNumber = intval($extractedNumberStr);
$extractedNumber++;
$extractedNumber = sprintf("%04d", $extractedNumber);
$extractedNumberStr = strval($extractedNumber);
$projectNo = $currentYearMonthStr . $extractedNumberStr;
}
else
{
$number = sprintf("%04d", 1);
$projectNo = $currentYearMonthStr . $number;
}
}
}
mysql_set_charset('utf8');
//query result
$result = insertProject($projectNo,$_SESSION['login_user'],$holdcode,$holdtitle,$projLeader,$projChecker,$holdremark);
// Check result
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$result = getLastProjectNo();
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$result = getLastProjectNo();
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if ($row_last = mysql_fetch_array($result))
{
$row_last[0] = cleanOutputData($row_last[0]);
$projectNo = $row_last[0];
if (is_array($holdprocess) || is_object($holdprocess))
{
foreach($holdprocess as $code => $eq)
{
$record = insertProcess($projectNo,$eq,$holdnumber[$code],$procLeader[$code],$procChecker[$code], $prodStuff[$code]);
if (!$record) {
die('Invalid query: ' . mysql_error());
}
}
}
}
}
我想是打破array.For例如一個數組裏面我有Array ([0] => aaronjames,adelyn [1] => benny,bryanooi)
我需要打破[0] => aaronjames,adelyn
到的東西,讓我來存儲每個名稱爲表中的每一行
需要一些更多的代碼 – sradha
請解釋一下,你想在上面提到的數組例子中爲DB存儲什麼值。 –
@sradha請參閱編輯張貼。謝謝 –