TeddyKiller Posted May 6, 2010 Share Posted May 6, 2010 I want to check the most recent 10, for current logged in user ($user->id) and if record found, delete it and continue with the insert query in my code. This means.. if a member is featured in 3rd place, and they purchased the place to be featured again.. they've be moved from 3, to 1. So.. their feature 3 place, would be deleted, with a new record put in. What i've got.. allows the user to be featured as many times as they want in the first 10. if(isset($_GET['submit'])) { if($user->credits < '1000') { echo '<span style="color:#e11919;>Not enough credits!</span>'; } else { $time = time(); $query = mysql_query("INSERT INTO `featured_member` (user_id, views, date) VALUES ('$user->id', '0', '$time')"); if($query) { $credits = $user->credits - 1000; $query = mysql_query("UPDATE `users` SET credits = '$credits' WHERE `id` = '$user->id'"); } } } How can I do it, thanks. Link to comment https://forums.phpfreaks.com/topic/200937-check-x-most-recent-and-do-some-operations/ Share on other sites More sharing options...
TeddyKiller Posted May 6, 2010 Author Share Posted May 6, 2010 Would this be the best method? Correct me if I'm wrong.. $query = mysql_query("select `id`, `user_id` from `featured_member` order by `date` desc LIMIT 10"); while($row = mysql_fetch_array($query)) { if($row['user_id'] == $user->id) { //Delete query } } Problem with this, is that it works.. but if there is less than 10 in the database.. i think it issues the error. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/jeanie/public_html/design/main.php on line 338 Link to comment https://forums.phpfreaks.com/topic/200937-check-x-most-recent-and-do-some-operations/#findComment-1054317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.