Results 1 to 1 of 1
Hi gurus, I need to call php function for fetching data from mysql but I dont want to move internal row pointer (IRP) forward. Or even get the actual IRP ...
- 04-16-2011 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 49
php stop "internal row pointer" when fetch from mysql
Hi gurus, I need to call php function for fetching data from mysql but I dont want to move internal row pointer (IRP) forward. Or even get the actual IRP position then fetch data and move IRP back to remembered position. Function mysql_data_seek() is not suitable for my example because I am trying to fetch data recursive here is code (See the pseudocode commented section):
For better understanding data in table looks like:Code:<?php include_once("connection.php"); $tree=""; $depth=1; $tempTree=""; // THIS RETURNS THE ROOTS FROM WHICH I WILL BEGIN $sql_query="SELECT DISTINCT(ppid) FROM process WHERE (ppid) NOT IN (SELECT pid from process);"; $nav_query = MYSQL_QUERY($sql_query); WHILE ( $nav_row = MYSQL_FETCH_ARRAY($nav_query) ) { //echo "calling build_child() from while with argument: " . $nav_row['ppid'] . "<br>"; $tree .= build_child($nav_row['ppid']); } FUNCTION build_child($ppID) { GLOBAL $depth, $tempTree; //$depth = $GLOBALS['depth']; //$tempTree = $GLOBALS['tempTree']; /* PSEUDOCCODE THAT SHOULD BE PASTED HERE: 1 FETCH ARRAY WITHOUT MOVING DATA POINTER AND STORE t_begin ADN t_end; 2 MAKE NEW SELECT INSTEAD CURRENT WHICH WILL CONTAINT STORED VALUES FROM PREVIOUS AS CONDITION */ // THIS SHOULD BE REPLACET WITH SOMETHING LIKE: // SELECT * FROM process WHERE ppid=2541 AND t_begin >= 1302865259 AND t_end <= 1302865269; // THE t_begin and t_end SHOULD COME FROM PREVIOUS SELECT WHICH DID NOT MOVE INTERNAL POINTER $sql_query = "SELECT * FROM process WHERE ppid=" . $ppID . ";"; $nav_query = MYSQL_QUERY($sql_query); WHILE ( $nav_row = MYSQL_FETCH_ARRAY($nav_query) ) { FOR ( $c=0;$c<$depth;$c++ ) { //$tempTree .= " "; $tempTree .= " - "; } $tempTree .= $nav_row['name'] . " (" . $nav_row['pid'] . ") <br>"; //echo "tempTree: " . $tempTree; $depth++; //echo "depth: " . $depth . "<br>"; //echo "calling build_child() from buildchild with argument: " . $nav_row['pid'] . "<br>"; build_child($nav_row['pid']); } $depth--; //echo "depth: " . $depth . "<br>"; RETURN $tempTree; } echo "<br>"; echo $tree; ?>
and at the output of php I would like something like ptree:Code:mysql> select * from process; +----+------------+------------+------+------+------------------------------+ | id | t_begin | t_end | pid | ppid | name | +----+------------+------------+------+------+------------------------------+ | 1 | 1302865260 | 1302865269 | 2544 | 2541 | bash-new-child1-child1 | | 2 | 1302865259 | 1302865269 | 2541 | 2510 | bash-new-child1 | | 3 | 1302865261 | 1302865269 | 2542 | 2510 | bash-new-child2 | | 4 | 1302800037 | 1302800049 | 2544 | 2541 | bash-old-child1-child1 | | 5 | 1302800036 | 1302800049 | 2541 | 2510 | bash-old-child1 | | 6 | 1302800038 | 1302800049 | 2542 | 2510 | bash-old-child2 | | 7 | 1302866248 | 1302866250 | 2546 | 2545 | bash2-child1 | | 8 | 1302866248 | 1302866250 | 2547 | 2546 | bash2-child1-child1 | | 9 | 1302866248 | 1302866250 | 2550 | 2545 | bash2-child2 | | 10 | 1302866248 | 1302866250 | 2551 | 2550 | bash2-child2-child1 | +----+------------+------------+------+------+------------------------------+ 10 rows in set (0.01 sec)
Code:2510 | - 2541 (bash-new-child1) | |- 2544 (bash-new-child1-child1) | | - 2542 (bash-new-child2) 2510 | - 2541 (bash-old-child1) | |- 2544 (bash-old-child1-child1) | | - 2542 (bash-old-child2) 2545 | - 2546 (bash2-child1) | | - 2547 (bash2-child1-child1) | | - 2550 (bash2-child2) | - 2551 (bash2-child2-child1)


Reply With Quote