Re: [請益] 請教陣列存取的問題消失
※ 引述《sweetjp6 (水餃)》之銘言:
: ※ 引述《gname ((′口‵)↗︴<><...<><)》之銘言:
: : 就用人腦CPU來解好了..XD
: : 以
: : $alldrama[0]['action'] = ["1", "2", "3"] ;
: : $alldrama[1]['action'] = ["4", "5"] ;
: : 為例
: : i的範圍在 0~1
: : $i=0 時
: : $alldrama[0]=["1", "2", "3"] ; <===這帶進去 $take 不會錯?
: : $i=1 時
: : $alldrama[1]=["4", "5"] ; <===這帶進去 $take 不會錯?
: 這邊應該是我交代不清楚。
: $alldrama = ["stand", "hunker"] ;
: 所以$take應該是要選擇出stand或者hunker的內容。
: : ^^^^^^^^^^^^
: : ^^^^^^^^^^^^^
: : 如果要 [] 就全部都 []
: : 如果要 [$j] 就全部都 [$j] 別混著用
: : 有時會演變成 debug 時的杯具~
: 這部分之所以[]和[$j]混用,是因為我認為
: 若寫成$action[$j] = $mergeDtl[$j]['action'] ;
: 會一直覆蓋到同一個元素內容。
: 因為我是期望可以一直儲存下去的。
: 因此這邊的$alldrama[0]['action'] 事實上應該是 stand['action']
: 這邊也是一樣 $alldrama[1]['action'] 等於 hunker['action']
: : 你想要的東西似乎用 array merge 可以實現, 但是我從你的程式碼中感覺不出來跟你
: : 想做的結果有什麼關聯? 有少PO東西嗎?
: : --------
ok.. 重新人腦debug...XD
$alldrama = ["stand", "hunker"] ;
for ($i=0 ; $i < sizeof($alldrama); $i++){
$take = "SELECT brand, action, sequence FROM robot where
screenplayname= '".$alldrama[$i]."' " ;
$result = mysql_query($take, $db_connect) ;
$many = mysql_num_rows($result) ;
for ($j=0 ; $j < $many ; $j++){
$mergeDtl[] = mysql_fetch_assoc($result) ;
$action[] = $mergeDtl[$j]['action'] ;
$brand[] = $mergeDtl[$j]['brand'] ;
}
}
i=0
$take = "SELECT brand, action, sequence FROM robot where
screenplayname= 'stand'" ;
$many=3
$j=0
$mergeDtl[0]=array('brand'=>?,'action'=>?,'sequence'=>?);
$action[0]=$mergeDtl[0]['action']
$j=1
$mergeDtl[1]=array('brand'=>?,'action'=>?,'sequence'=>?);
$action[1]=$mergeDtl[1]['action']
$j=2
$mergeDtl[2]=array('brand'=>?,'action'=>?,'sequence'=>?);
$action[2]=$mergeDtl[2]['action']
===============================================================
i=1
$take = "SELECT brand, action, sequence FROM robot where
screenplayname= 'hunker'" ;
$many=3
$j=0
$mergeDtl[3]=array('brand'=>?,'action'=>?,'sequence'=>?);
$action[3]=$mergeDtl[0]['action']
$j=1
$mergeDtl[4]=array('brand'=>?,'action'=>?,'sequence'=>?);
$action[4]=$mergeDtl[1]['action']
$j=2
$mergeDtl[5]=array('brand'=>?,'action'=>?,'sequence'=>?);
$action[5]=$mergeDtl[2]['action']
知道問題在哪裡了嗎?
===============補充分隔線=============
關於
for ($j=0 ; $j < $many ; $j++){
$mergeDtl[] = mysql_fetch_assoc($result) ;
$action[] = $mergeDtl[$j]['action'] ;
$brand[] = $mergeDtl[$j]['brand'] ;
}
這段, 我腦內有個寫法,但不知道能不能動...XD
list($brand[],$action[],$a)=mysql_fetch_row($result) ;
list 那邊可能會過不去...囧"
--
※ 發信站: 批踢踢實業坊(ptt.cc)
→
04/24 13:51, , 1F
04/24 13:51, 1F
(應推文要求...XD)
※ 編輯: gname 來自: 120.119.112.114 (04/24 13:53)
推
04/24 13:55, , 2F
04/24 13:55, 2F
※ 編輯: gname 來自: 120.119.112.114 (04/24 14:03)
※ 編輯: gname 來自: 120.119.112.114 (04/24 14:05)
→
04/24 14:19, , 3F
04/24 14:19, 3F
→
04/24 14:20, , 4F
04/24 14:20, 4F
推
04/24 14:23, , 5F
04/24 14:23, 5F
→
04/24 14:24, , 6F
04/24 14:24, 6F
→
04/24 14:25, , 7F
04/24 14:25, 7F
→
04/24 14:27, , 8F
04/24 14:27, 8F
推
04/25 16:41, , 9F
04/25 16:41, 9F
→
04/25 20:51, , 10F
04/25 20:51, 10F
→
04/25 21:00, , 11F
04/25 21:00, 11F
→
04/25 21:56, , 12F
04/25 21:56, 12F
→
04/25 23:31, , 13F
04/25 23:31, 13F
→
04/25 23:32, , 14F
04/25 23:32, 14F
→
04/25 23:32, , 15F
04/25 23:32, 15F
→
04/25 23:32, , 16F
04/25 23:32, 16F
→
04/25 23:34, , 17F
04/25 23:34, 17F
→
04/26 09:01, , 18F
04/26 09:01, 18F
討論串 (同標題文章)
PHP 近期熱門文章
PTT數位生活區 即時熱門文章