3raser Posted June 20, 2010 Share Posted June 20, 2010 Here is my code if(isset($_SESSION['admin']) || $authorized || isset($_SESSION['mod'])) { $ids = implode(', ', $_POST['post']); $error = false; foreach($_POST['post'] as $thread) { if(!is_numeric($thread)) { $error = true; break; } } if(!$error) { switch($_POST['action']) { case 'delete': $get_poster = mysql_query("SELECT author FROM posts WHERE id IN ($ids)"); $action_lower = mysql_query("UPDATE users SET dp = dp - 0.005 WHERE id IN ($get_poser)"); if(mysql_query("DELETE FROM {$prefix}posts WHERE id IN ($ids)")) { echo '<p>Post(s) successfully deleted. <a href="index.php">Back to forum</a>.</p>'; } break; default: echo '<p>You have not selected an action. <a href="index.php">Click Here</a> to go to the forum index</p>'; } } else { echo '<p>You have chosen invalid IDs. Please choose new ones <a href="index.php">here</a>.'; } } else { echo '<p>You need to be logged in as an administrator or moderator to do this.</p><p><a href="login.php">Click Here</a> to log in.'; } As you see, I'm trying to get all the authors for each post selected, which is $ids. How would I make it so it updates every users points to be - 0.005? - I'm trying to do that at $action_lower Quote Link to comment https://forums.phpfreaks.com/topic/205362-updating-donator-points-to-be-lower/ Share on other sites More sharing options...
Alex Posted June 20, 2010 Share Posted June 20, 2010 You can do it with just one query like this: UPDATE users SET dp = dp - 0.005 WHERE id IN ($ids) Quote Link to comment https://forums.phpfreaks.com/topic/205362-updating-donator-points-to-be-lower/#findComment-1074758 Share on other sites More sharing options...
3raser Posted June 20, 2010 Author Share Posted June 20, 2010 You can do it with just one query like this: UPDATE users SET dp = dp - 0.005 WHERE id IN ($ids) Not really. I need to get the users username first. $ids is the post selected. Quote Link to comment https://forums.phpfreaks.com/topic/205362-updating-donator-points-to-be-lower/#findComment-1074762 Share on other sites More sharing options...
Alex Posted June 20, 2010 Share Posted June 20, 2010 You need to explain better then, because your code really doesn't make any sense. You're selecting the author's names and then comparing it against the id column.. The ids of the posts selected should correspond to the ids of the rows you want to update, no? Quote Link to comment https://forums.phpfreaks.com/topic/205362-updating-donator-points-to-be-lower/#findComment-1074763 Share on other sites More sharing options...
3raser Posted June 20, 2010 Author Share Posted June 20, 2010 You need to explain better then, because your code really doesn't make any sense. You're selecting the author's names and then comparing it against the id column.. The ids of the posts selected should correspond to the ids of the rows you want to update, no? No. 1) A moderator selects one or multiple posts. 2) They click "GO" 3) $ids is basically getting all or one of the posts selected 4) I'm trying to extract the info for EACH post selected $get_poster = mysql_query("SELECT author FROM posts WHERE id IN ($ids)"); 5) I'm trying to update the points for each post author (basically getting all of the authors for each post in $get_poster) using this mysql_query: $action_lower = mysql_query("UPDATE users SET dp = dp - 0.005 WHERE id IN ($get_poser)"); Quote Link to comment https://forums.phpfreaks.com/topic/205362-updating-donator-points-to-be-lower/#findComment-1074766 Share on other sites More sharing options...
Alex Posted June 20, 2010 Share Posted June 20, 2010 Oh, sorry I didn't realize that you were dealing with two different tables. So the author column on the posts table corresponds to the id column on the users table? UPDATE users SET dp = dp - 0.005 WHERE id IN (SELECT author FROM posts WHERE id IN ($ids)) Quote Link to comment https://forums.phpfreaks.com/topic/205362-updating-donator-points-to-be-lower/#findComment-1074770 Share on other sites More sharing options...
3raser Posted June 21, 2010 Author Share Posted June 21, 2010 Oh, sorry I didn't realize that you were dealing with two different tables. So the author column on the posts table corresponds to the id column on the users table? UPDATE users SET dp = dp - 0.005 WHERE id IN (SELECT author FROM posts WHERE id IN ($ids)) Parse error: syntax error, unexpected T_STRING in /home/hero/public_html/forums/post_config.php on line 110 if(isset($_SESSION['admin']) || $authorized || isset($_SESSION['mod'])) { $ids = implode(', ', $_POST['post']); $error = false; foreach($_POST['post'] as $thread) { if(!is_numeric($thread)) { $error = true; break; } } if(!$error) { switch($_POST['action']) { case 'delete': if(mysql_query("DELETE FROM {$prefix}posts WHERE id IN ($ids)")) { mysql_query(UPDATE users SET dp = dp - 0.005 WHERE id IN (SELECT author FROM posts WHERE id IN ($ids))); echo '<p>Post(s) successfully deleted. <a href="index.php">Back to forum</a>.</p>'; } break; default: echo '<p>You have not selected an action. <a href="index.php">Click Here</a> to go to the forum index</p>'; } } else { echo '<p>You have chosen invalid IDs. Please choose new ones <a href="index.php">here</a>.'; } } else { echo '<p>You need to be logged in as an administrator or moderator to do this.</p><p><a href="login.php">Click Here</a> to log in.'; } Quote Link to comment https://forums.phpfreaks.com/topic/205362-updating-donator-points-to-be-lower/#findComment-1074791 Share on other sites More sharing options...
Alex Posted June 21, 2010 Share Posted June 21, 2010 You forgot the quotes.. mysql_query("UPDATE users SET dp = dp - 0.005 WHERE id IN (SELECT author FROM posts WHERE id IN ($ids))"); Quote Link to comment https://forums.phpfreaks.com/topic/205362-updating-donator-points-to-be-lower/#findComment-1074795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.