【发布时间】:2011-02-17 19:45:29
【问题描述】:
我在不同的 MYSQL 表中有两组数组。这就是我想做的事情
What I Want TO Do
TABLE_ONE connect to the table.
get the value we want from session_id
THEN get the array associated with the value (session_id)
explode the array to get individual values.
NOW::::: - GO TO TABLE_TWO
TABLE_TWO Go straight to the first value from array (TABLE_ONE)
Explode the array associated with it.
Delete the number that's equal to the session_id
_____________________________________________________
And so fort....
下面更直观的解释:
session_id = 4
TABLE_ONE:
id array1
1 4
2 1
3 2,5
4 1,3,4,5
5 4,5
TABLE_TWO:
id array2
1 4,6,9,2
2 3,7,8,2
3 7,12,4,9
4 1,5,4,8
5 3,6,12,3,5,4
所以,因为 session_id = 4,我们转到 TABLE_ONE id 4。 id-4 的数组是 1,3,4,5。
所以现在我们知道 4 可以在id 1,3,4,5 of TABLE_TWO 中找到
我们现在应该分解 TABLE_TWO 的数组并从那里的数组中删除 4。内爆数组并将新值保存到数据库。
这就是我所做的 - 它只会从 id-3 中删除“4”并删除 id-4 中的所有值。请帮忙!!
$SESSION = 4;
$depSQL = mysql_query("SELECT array1 FROM TABLE_ONE WHERE id='$SESSION' LIMIT 1");
while($row=mysql_fetch_array($depSQL)) { $depARRAY = $row["array1"]; }
$explodedDEP = explode(",", $depARRAY);
foreach ($explodedDEP as $key1 => $value1) {
$stSQL = mysql_query("SELECT array2 FROM TABLE_TWO WHERE id='$value1'");
while($get=mysql_fetch_array($stSQL)) { $stARRAY = $get["array2"];}
$explodedST = explode(",", $stARRAY);
foreach ($explodedST as $key2 => $value2) {
if ($value2 == $SESSION) {
unset($explodedST[$key2]);
}
}
$newST = implode(",", $explodedST);
$sql = mysql_query("UPDATE TABLE_TWO SET array2 ='$newST' WHERE id='$value2'");
}
exit();
请帮忙!!!我真的很挣扎。 我已经尝试了几个小时,但我还没有真正得到任何地方。 我认为问题在于插入数据库。 请帮忙。
【问题讨论】:
-
$SESSION = 4应该是$SESSION['id'] = 4;。
标签: mysql arrays loops foreach implode