Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it L'avatar di Threepwood
    Registrato dal
    Feb 2003
    Messaggi
    2,107

    [Mysql] Update solo il primo che...

    Salve a tutti!

    come faccio per fare una query di questo tipo

    codice:
    UPDATE TABELLA set CAMPO= 1 WHERE CAMPO=2 LIMIT 0,1
    in pratica un aggiornamento solo sulla prima riga che rispetta una condizione... col LIMIT non mi funzia, mi dice come è?

    danke!


    [parentesi: uso mysql 4.0.12]
    Guybrush Threepwood

  2. #2
    un semplice esempio di come aggirare il problema. la funzione particolare non la ricordo ma sicuramente qualcuno a breve la posta.

    Codice PHP:
    $query "SELECT * FROM TABELLA WHERE Campo=2 Limit 0,1";
    $result mysql_query($query$db); 
    $row mysql_fetch_array($result);

    $query "UPDATE TABELLA Set Campo = 1 WHERE ID_CAMPO = '$row[ID_CAMPO]'";
    $result mysql_query($query$db); 
    $row mysql_fetch_array($result); 
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  3. #3
    Utente di HTML.it L'avatar di Threepwood
    Registrato dal
    Feb 2003
    Messaggi
    2,107
    non è che c'è un modo dirett con un singolo update?
    Guybrush Threepwood

  4. #4
    codice:
    UPDATE TABELLA set CAMPO = 1 
    WHERE CAMPO = 2 
    LIMIT 1
    Limiti ad 1 riga... potresti anche usare ORDER BY ... ASC/DESC per ordinare il record da modificare.

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  5. #5
    Utente di HTML.it L'avatar di Threepwood
    Registrato dal
    Feb 2003
    Messaggi
    2,107
    GRANDE! non avevo pensato di togliere lo "0,"
    danke!!
    Guybrush Threepwood

  6. #6
    heheh visto? qualcuno t ha postato il metodo unico!
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.