How to get the values and proceed to the next incrementing id at the same time in mysql using select st

I’m currently facing a problem in mysql. I have this first id that i got from jquery which is like 398(from user1) and so on incrementing till 700 with other users input too. i managed to pass the grabbed value from jquery to the mysql query. But, here is the problem i need to increment the value of the id from 398 to the next id which is 400(the next id is randomly 405) i can’t seem to find a good soln on the internet after googling. The soln’s are too abstract for me. So, far, couldn’t understand how i can select from updates table the correct next incrementing id pertaining to that user1&user2. is, there a way to do it in mysql with the jquery value which isn’t incrementing, using php is also good for me.

here is the mysql query:

public function totalUpdates($friend,$session,$update_id1,$update_id2, $load) {
    try{
    $sql2="SELECT distinct update_id,update_body,time,title,user_id_u,account_name,author,data FROM updates where author in (:friend,:session) and update_id not in(:update_id1, :update_id2) order by time desc limit $load,2";
        $stmth=  $this->_db->prepare($sql2);//Check here syntax of $db 
    $stmth->bindValue(":session",$session);
    $stmth->bindValue(":friend",$friend);
    $stmth->bindValue(":update_id1",$update_id1);
    $stmth->bindValue(":update_id2",$update_id2);
    $stmth->execute();
    return $stmth->fetchAll();
    } catch (PDOException $ei){
        echo $ei->getMessage();
    }
}

could you please rephrase the question

@r937 ok, here is the scenario i get first and last loaded id value from posts in jquery through DOM. The problem is, it is producing duplicate id and posts because of it only able to get the first loaded posts id in the class and i couldn’t think of a way to use jquery to get the newly loaded post’s first id as it supports only first() and gets the class’s old first loaded post and not newly loaded first post’s id . Hence, i thought of using mysql query to get an unique new post’s id after the last loaded old first post id got through jquery. so that i can prevent duplicate entries and then pass it to the class in the php script(i’m planning to use separate query to get the newly to be posted post’s id after the old id) and the problem is i’m master of none hence facing the problem of how to get it.

in this query’s case i want to change the value of $update_id1 to the next new to be posted id of the same user eg) $friend or $session.

someone else will have to help you, this just doesn’t make any sense to me at all, sorry

@r937 no probs, thanks anyway.

Why?
Autoincrementing fields don’t need to be sent in INSERT queries - the database engine will take care of populating that field.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.