numan82 Posted December 3, 2007 Share Posted December 3, 2007 Hi, I want to convert the Adbodb built in functions into MySQL functions. what is the equivalent solution. function buildTree_parent($treeBranch) { $query = "SELECT * FROM links WHERE address='$treeBranch'"; $this->db->SetFetchMode(ADODB_FETCH_ASSOC); $branches_rs =& $this->db->Execute($query); while(!$branches_rs->EOF) { $branches[] = $branches_rs->fields; $branches_rs->MoveNext(); } return $branches; } Please Post your replies! Thanks! Quote Link to comment Share on other sites More sharing options...
trq Posted December 3, 2007 Share Posted December 3, 2007 <?php function buildTree_parent($treeBranch) { $query = "SELECT * FROM links WHERE address = '$treeBranch'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc) { $branches[] = $row; } } } return $branches; } ?> Quote Link to comment Share on other sites More sharing options...
numan82 Posted December 3, 2007 Author Share Posted December 3, 2007 that great! let me clarify one more thing about it for the adodb function MoveNext(); we should have $row++. Right or wrong? function buildTree_parent($treeBranch) { $query = "SELECT * FROM links WHERE address = '$treeBranch'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc) { $branches[ ] = $row; $row++; } } } Thanks once again for the response! return $branches; } Quote Link to comment Share on other sites More sharing options...
trq Posted December 3, 2007 Share Posted December 3, 2007 for the adodb function MoveNext(); we should have $row++. Right or wrong? No. while ($row = mysql_fetch_assoc($result) { (There was a type in my original post) Effectively does the same thing. A call to mysql_fetch_assoc() retrieves the current row, then moves the internal pointer one place forward. having it in a while loop will cause it to move through each record untill there are no records left. Quote Link to comment Share on other sites More sharing options...
numan82 Posted December 4, 2007 Author Share Posted December 4, 2007 Thanks for the response! I'm surprised why I'm unable to get the all records with this code $query = "SELECT * from links"; $result = mysql_query($query) while($row=mysql_fetch_assoc($result)) { $branches =$row; } return $branches; The $branches don't have any record in it, I invoked it by calling this parameter but I'm unable to see any record if do like this $branches[] = $row["Column Name"]; than it shows the value of this column. but I want to have all the records of this table in my $branches array. Thanks! keep smile Quote Link to comment Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 <?php function buildTree_parent($treeBranch) { $query = "SELECT * FROM links WHERE address = '$treeBranch'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc) { $branches[] = $row; } } } return $branches; } $branches = buildTree_parent('foo'); // $branches is now an array containing all records. print_r($branches); ?> Quote Link to comment Share on other sites More sharing options...
numan82 Posted December 4, 2007 Author Share Posted December 4, 2007 class Tree{ function buildTree_parent($treeBranch) { $query = "SELECT * FROM links WHERE address = '$treeBranch'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc) { $branches[] = $row; } } } return $branches; } }// end class definition $mytreeObj = new Tree; $test = $mytreeObj->buildTree_parent($parent); echo $test; // now it should show all the records } Quote Link to comment Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 In your example, $test is an array. You need to loop through that array to get all records. Quote Link to comment Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 It is in fact a multidimensional associative array. An example of looping through it would be (I don't know the names of the fields in your db so I'll just use fl1 fld2 etc etc).... <?php $mytreeObj = new Tree; if ($test = $mytreeObj->buildTree_parent($parent)) { foreach($test as $data) { echo "<p>"; echo $data['fld1']."<br />"; echo $data['fld2']."<br />"; echo $data['fld3']."</p>"; } } ?> Quote Link to comment Share on other sites More sharing options...
numan82 Posted December 5, 2007 Author Share Posted December 5, 2007 hi, thanks for all responses and replies I solved the problem and the only mistake that I was not passing the return type to mysql_fetch_array($result,MYSQL_BOTH)// MYSQL_BOTH is is the return type for both numric and associative array. it is solved now. Thanks for your hard work and co-operation class Tree{ function buildTree_parent($treeBranch) { $query = "SELECT * FROM links WHERE address = '$treeBranch'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result,MYSQL_BOTH)) { $branches[] = $row; } } } return $branches; } }// end class definition $mytreeObj = new Tree; $test = $mytreeObj->buildTree_parent($parent); print_r($test); // now it will show all the records } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.