update php and mysql form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saadsinpk
    New Member
    • Jan 2010
    • 12

    update php and mysql form

    hi i need help in making update script
    i don't want form or any thing i want that user get active by admin, when admin visit player-update.php it update all user
    here is code i am using

    Code:
        $query = "SELECT join_survivor.join_user, join_survivor.join_pool, join_survivor.join_done, join_survivor.join_fight, events_fights.event_id, join_survivor.join_event, events_fights.fight_id, join_survivor.join_win, join_survivor.join_lost, events_fights.win, events_fights.lost, survivor_events.event_id, survivor_events.event_period, join_survivor.join_pick ".
        "FROM join_survivor, events_fights, survivor_events ".
           "WHERE join_survivor.join_pick = '1' AND join_survivor.join_done = '0' AND events_fights.event_id = join_survivor.join_event AND join_survivor.join_event = survivor_events.event_id AND survivor_events.event_period = 'past' AND join_survivor.join_win = events_fights.lost  AND join_survivor.join_fight = events_fights.fight_id";
    
    
        $result = mysql_query($query) or die(mysql_error());
        while($row = mysql_fetch_array($result))
        {
        mysql_query(" UPDATE join_survivor SET join_done ='1', join_pick='0' WHERE join_done = '0' AND join_pick = '1' AND event_period = 'past'");
        mysql_query($query) or die ('Same entry please go back');
        }

    the problem is this when join_survivor.j oin_win = events_fights.l ost it update whole table, i want that it only update that user only please help me out, if u don't understand let me know, because i have really bad english
    thanks in advance
  • John Doe
    New Member
    • Jun 2011
    • 20

    #2
    Somewhere, you need to be limiting your SQL to the relevant User ID's which isn't mentioned anywhere in the sql you posted.

    First, you are performing an unnecessary SELECT operation which doesn't do anything for you other than retrieve some records from the database, but these don't relate to your UPDATE clause in any way.

    Then, you are performing an UPDATE which runs exactly the same command over and over. You probably need something in your WHERE clause for the UPDATE that tells it which users you are trying to update (and get rid of the WHERE loop).

    Tip: You can also shorten your SQL quite a bit by using 'table aliases'. Eg..
    Code:
    SELECT js.join_user, ef.event_id FROM join_survivor AS js, events_fights AS ef WHERE ef.event_id = '67'

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      In order to avoid update problem follow two approaches
      1. always use a recordid which is primary and auto incremental
      2. update as follow: "UPDATE [TABLE] SET field1='..', ... WHERE [conditions] LIMIT 1";
      3. Incase of delete do the same: "Delete FROM [TABLE] WHERE [conditions] LIMIT 1"

      Comment

      Working...