SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    fun one! last person to text number

    I have two tables

    userpie_history which is set out

    to,user,message,date,ip,useragent

    userpie_incoming which is set out
    from,mesage,date,user_id

    what i want to do is grab the number that has come in and find the last person that sent a message to them and then take the user and insert it in to the user_id field on userpie_incoming.

    by default when a new incoming message comes in it sets the user_id as null.

    hopefully i have explained enough for some one to understand all date's are set via CURRENT_TIMESTAMP

  2. #2
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i got the following for grabbing the last message sent to a number
    Code:
    SELECT * 
    FROM  `userpie_history` 
    WHERE  `to` =  '077123456789'
    ORDER BY  `userpie_history`.`date` DESC 
    LIMIT 0 , 1

  3. #3
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solved in the end
    PHP Code:
    $findlast $db2->prepare("SELECT * FROM  `userpie_history` WHERE  `to` = :from ORDER BY  `userpie_history`.`date` DESC LIMIT 0 , 1");
    $findlast->bindParam(':from'$from3);
    $findlast->execute();
    $match $findlast -> fetch();
    $userid $match["user"];

    if (
    $userid == "")
    {
    echo 
    "No User found";
    exit();
    } else {
    echo 
    $userid;
    }
    $assignid $db2->prepare("UPDATE `userpie_incoming` SET  `user_id` = :userid WHERE `from` = :from AND `user_id` IS NULL LIMIT 1 ");
    $assignid->bindParam(':userid'$userid);
    $assignid->bindParam(':from'$from3);
    $assignid->execute();
    echo 
    "Updated Incoming Message"

  4. #4
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,250
    Mentioned
    240 Post(s)
    Tagged
    1 Thread(s)
    Glad that you found the answer and that you were kind enough to post it. Sorry that I didn't see your message before but it is good to see that you didn't give up until you found the solution


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •