[RESOLVED] Select and update with one query
Results 1 to 4 of 4

Thread: [RESOLVED] Select and update with one query

  1. #1
    Senior Member
    Join Date
    Apr 2009
    Location
    Gran Canaria
    Posts
    103

    resolved [RESOLVED] Select and update with one query

    Hello,

    I am wondering if it's possible in MySQL to combine SELECT and UPDATE statements in one query?

    Thanks.

    PHP Code:
    $result mysql_query"SELECT id, file FROM random_images 
    where city='
    $city' ORDER BY last_showed ASC limit 0, 1") or die(mysql_error());

    list(
    $lid$file) = mysql_fetch_row($cats);

    $update=mysql_query("UPDATE random_images SET last_showed='$time
    WHERE id='
    $lid'") or die(mysql_error()); 

  2. #2
    Senior Member dagon's Avatar
    Join Date
    Nov 2001
    Posts
    6,178
    you can separate them with a ; (http://www.dev-explorer.com/articles...-mysql-queries) and send them in one go but it really would save only nanoseconds and would have more potential problems than its worth. Kind of difficult if your expecting to get any results back :-)
    Last edited by dagon; 05-26-2009 at 04:23 PM.

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Location
    Gran Canaria
    Posts
    103
    Thank you very much.

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,414
    Also note that since the mysql lib was deprecated in favor of the mysqli library, you could instead update your code and use something like mysqli_multi_query.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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