title: Can an inner loop in a mysql procedure use the result of the outer loop
body: <p>I have tried to create the following procedure in mysql</p>
  
  <pre><code>    PROCEDURE fix()
  BEGIN
  
    DECLARE event_id_ INT;
    DECLARE gate_number INT;
  
    DECLARE l_done          INT DEFAULT  0;
    DECLARE curs_event_id CURSOR FOR SELECT DISTINCT event_id FROM history_15min;
    DECLARE curs_gate_number CURSOR FOR SELECT DISTINCT gate_number 
                                           FROM history_15min WHERE event_id =event_id_;
   ( -- HERE IS THE PROBLEM - event_id_ IS BLANK THERE FOR  THE INNER LOOP RETURNS NO RESULTS ....)            
  
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_done=1;  
  
      OPEN curs_event_id;
      event_loop : LOOP
      FETCH curs_event_id INTO event_id_;
      IF l_done=1 THEN LEAVE event_loop;
      END IF;
  
          OPEN curs_gate_number;
          gate_loop : LOOP
          FETCH curs_gate_number INTO gate_number;
          IF l_done=1 THEN LEAVE gate_loop;
          END IF;
  
  insert into t value ('1');
  
          END LOOP gate_loop;
          CLOSE curs_gate_number;
          SET l_done=0;
  
      END LOOP event_loop;
      CLOSE curs_event_id;
  
  END
  </code></pre>
  
  <p>Is there a way i can get the result from the first loop to be a variable in the second loop ??</p>