我在不同的 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
表一:
id array1
1 4
2 1
3 2,5
4 1,3,4,5
5 4,5
表_二:
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();
请帮忙!!!我真的很挣扎。我已经尝试了几个小时,但我还没有真正得到任何地方。我认为问题在于插入数据库。请帮忙。