title: Perl fetch without execute error - at end of execution
body: <p>My current perl code is running through all of the rows of the database query and then throwing a </p>
  
  <pre><code>DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at ./recieveTxn.cgi 
  line 168.
  </code></pre>
  
  <p>At the end. It almost is like there's something that's not telling the loop to stop at the end of the rows, but I have written it just as the others.</p>
  
  <p>So for example: The query would pull up</p>
  
  <p>shortcode1<br />
  shortcode2<br />
  shortcode3<br />
  then throw the error here</p>
  
  <pre><code>$sql = "
      SELECT
          aPI.folder AS aPIfolder, 
          aPI.rowNum AS aPIrowNum,
          hasInput,
          evalCode
      FROM
          aPersonalItems as aPI
      LEFT JOIN 
          pItems_special_inputs as SI 
      ON
          aPI.folder = SI.folder AND
          aPI.rowNum = SI.rowNum
      WHERE
          hasInput=1 AND
          aPI.folder='$FORM{'folder'}'
      ORDER BY
          aPI.rowNum
  ";
  
  $sth = $dbh-&gt;prepare( $sql );
  $sth-&gt;execute();
  
  my ($shortcoderow, $row);
  my $shortcodeSQL = "
      SELECT 
          * 
      FROM
          pItemsShortCodes 
      WHERE
          folder='$FORM{'folder'}' 
      ORDER BY
          rowNum
  ";
  my $shortcodeSTH = $dbh-&gt;prepare( $shortcodeSQL );
  $shortcodeSTH-&gt;execute();
  
  while( my $ref = $sth-&gt;fetchrow_hashref() ) {
  
      my $shortCode;
      my $isblank = 1;
      my $rowNum  = $ref-&gt;{'aPIrowNum'};
  
      while(my $shortcodeRef = $shortcodeSTH-&gt;fetchrow_hashref())
      #&amp;&amp; $rowNum == $shortcodeRef-&gt;{'rowNum'}) #line 168 above
      {
          $shortCode=$shortcodeRef-&gt;{'shortcode'};
          print $shortCode."\n";
      }
      $shortcodeSTH-&gt;finish();
  }
  </code></pre>