• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

mySQL apposition ID readings under PHP

horizon

n00b
Joined
Sep 4, 2006
Messages
2
Hi,

horizon said:
The following request might be one of the most complicated task I'm about to request. I have searched over this section on the forum to see if there were any results on this subject but none was not (at least - not - to what I'm specifically looking for).

Here's the thing.

I have created an HTML form with checkboxes, built an array - pointing to the targeted action under PHP, even imploded the array results. All is working well so far. I have even set the array, from the targered action, in order to get ready to clear the specific readings to be cleared out (deleted).

However, this works only with individual values for each SQL fields.

The way I'm trying to delete these entries is like the following:

user_id: 1,2,3,4,5,6,7 ...

and so on (so - all appositions from the same lines under a specific SQL table for each users.

As you can see, from the example above, I have '7' numbers. What I'd like to do is to delete, for example, two entries like this:


Now, what I'd like to do is to capture the rest of the IDs:

1,2,3,4,6

and be able to update / delete them to / from that field_id without having to re-import the cleared out fields (which I have been unsuccessful so far).

Is there anyway this could be done without affecting the whole row itself ? I have already tried using the 'NOT IN' command through the SQL statement but without success. The removed values keeps coming back on anyhow. I know I'm missing something but I'd like to know what could be the best solution to clear out these two readings for good.

Anyone who could help me on this would be greatly appreciated.

Thanks !

In the mean time, here's a sample code:

PHP:
if (isset($_POST['user_id'])) {
$user_id = (isset($_POST['user_id']) && (is_array($_POST['user_id']))) ? $_POST['user_id'] : 0;
} else {
$user_id = 0;
}

if (!is_array($user_id)) {
die ('No permission');

} else {

$user_ids = implode(",", $user_id);

$sql = "

SELECT user_id
FROM table
WHERE id = ".$_SESSION['user_id'];

$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
$user_id_field = $row['user_id'];
}

$top_user_id_array = explode(",", $user_id_field);

if (!empty($user_id_field)) {

$sql_update = "

UPDATE table
SET user_id = '".$user_id_field."'
WHERE user_id IN (".$user_ids.") AND id = ".$_SESSION['user_id'];

$result = mysql_query($sql_update);

}
}

if ($result) {
header("Location: index.php");
}

As you can see, it is not quite what I expected but, if someone could help me to accomplish this, it would be greatly appreciated. :)
 
Back
Top