1

Hey i'm trying to call a procedure in a for loop but keep stumbling at the same error i've tried several things but just can't find the problem. here's a piece of my code

php:

     for ($x=1; $x<=16; $x++)
  {
      $rs = mysql_query("CALL sp_programma(".$x.")");
      $tmp='row'.$x;
      $$tmp = mysql_fetch_array($rs);
  } 
 ?>
<body>



<div id="schoten">
<div class="plaats">Schoten</div>
<div class="dag">Maandag
<div class="les" id="S1"><?php echo $row1['Uur']; echo '</br>'; echo $row1['Omschrijving']; echo '</br>'; echo $row1['Omschrijving_grpnaam'] ?></div>
<div class="les" id="S2"><?php echo $row2['Uur']; echo '</br>'; echo $row2['Omschrijving']; echo '</br>'; echo $row2['Omschrijving_grpnaam'] ?></div>

and the stored procedure:

DROP PROCEDURE IF EXISTS circant.sp_programma;
CREATE PROCEDURE circant.`sp_programma`(param_name int)
BEGIN
    SELECT tbl_groepen.Omschrijving_grpnaam, tbl_lessoorten.Omschrijving, tbl_lessen.Uur
  FROM (circant.tbl_groepen tbl_groepen
        INNER JOIN circant.tbl_lessen tbl_lessen
           ON (tbl_groepen.ID = tbl_lessen.GroepID))
       INNER JOIN circant.tbl_lessoorten tbl_lessoorten
          ON (tbl_lessoorten.ID = tbl_lessen.Les_soort_ID)
          where tbl_groepen.ID = param_name;
END;

only the first works (row1) but then for row2 and so on i get the error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Circant_beter\Agenda.php on line 18

does any body know what i'm doing wrong?

Sennevds
  • 83
  • 10
  • Did you try to call the procedure with values > 1 directly in mysql ? If there's no result, then I think mysql_fetch_array will return false (thus a boolean, not a resource) – Hugehornet Oct 02 '13 at 11:41
  • If i put 2 instead of $x it works so the stored procedure is working – Sennevds Oct 02 '13 at 11:43
  • i've read the other question but tried every solution but it isn't working – Sennevds Oct 02 '13 at 12:05
  • I've found a solution. it was not a duplicate question. Every time a loop ends the connection with mysql is closed down so you have to open the mysql connection in your loop – Sennevds Oct 03 '13 at 14:17
  • ...I'm not really sure that's the expected behaviour from mysql_fetch_array(). :3 – Hugehornet Oct 04 '13 at 07:27

0 Answers0