Jump to content

check X most recent and do some operations


TeddyKiller

Recommended Posts

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.