function - PHP Recursive query script -


I want to create a recursive query scripts which output to ID_Col2 Will be followed in the next recurring query. My code which actually only prevents the first cycle:

  function recurring ($ id, $ numRows) {for ($ i = 0; $ i & lt; = $ numrows; $ i ++) {$ DbConnect = New MySqlConnect (); $ DbConnect- & gt; Connect (); $ Query = $ dbConnect-> Query ("SELECT ID_Col1, ID_Col2 wbs WHERE ID_Col1 = '" $ id. "' And ID_Col2! = '0' Order by ID ASC); $ N = mysql_num_rows ($ query); $ Result = $ dbConnect-> Remove Object ($ query); ($ X = 0; $ x & lt; Count ($ result); $ x ++) {$ r = $ result [$ x] - & gt; ID_Col2; Echo $ r '& lt; Br> & # 39; & # 39; Recurring recurring query ($ r, $ n); } $ DbConnect- & gt; Disconnect (); }} Echo recursiveQuery ('6765', '25');  

So how do I modify this script to make it work?

You open the database connection again ...:

  Function recursive CQ ($ ID, $ numRows) {$ dbConnect = New MySqlConnect (); $ DbConnect- & gt; Connect (); ($ I = 0; $ i & lt; = $ numrows; $ i ++) for {//} ($ x = 0; $ x & lt; count ($ result); $ x + +) {// [..] Return recurring security ($ r, $ n); } $ DbConnect- & gt; Disconnect (); }}  

I can not tell you how to do this because it should not work.

You should open / close the connection outside the recurring part of your code.


Edit

Correct code:

  function recursive scan ($ id, $ numrows, $ dbconnect) {for ($ i = $; $ I & lt; = $ numrows; $ i ++) {//] ($ x = 0; $ x & lt; count ($ result); $ x ++) { // [...] // Here you do not want to refund, but only to execute: Recursive scan ($ r, $ n, dbConnect); }}} Function wrapfank ($ id, $ numRows) {$ dbConnect = new MySqlConnect (); $ DbConnect- & gt; Connect (); // nothing is given by your function (ekos directly in code) recursive ($ id, $ numrows, $ dbconnect); $ DbConnect- & gt; Disconnect (); } Rapfunc ('6765', '25');  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -