Jump to content

[SOLVED] Converting Adodb functions into MySQL functions


numan82

Recommended Posts

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!

Link to comment
Share on other sites

<?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;
}

?>

Link to comment
Share on other sites

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;

}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ;D

Link to comment
Share on other sites

<?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);

?>

Link to comment
Share on other sites

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

 

 

 

}

Link to comment
Share on other sites

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>"; 
    }
  }

?>

Link to comment
Share on other sites

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

 

 

 

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.