Web Analytics Made Easy -
StatCounter php equivalient recordset.movefirst - CodingForum

Announcement

Collapse
No announcement yet.

php equivalient recordset.movefirst

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • php equivalient recordset.movefirst

    what i want to know is what the equivelent to asp's recordset.movefirst is in php?
    I'm accessing my query results with mysql_fetch_array but as I understand it, ever time that function is called it gets the next row, how do I move back to the first row to resuse the same result set without requerying the database?
    http://www.hazelryan.co.uk

  • #2
    mysql_data_seek()
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

    Comment


    • #3
      Cache your result set when advancing to the next row.

      Easiest way to do this is by creating a represantative class for the mysql(i) result set class with own fetch_XXX()-functions.

      Something like this: (untested)
      PHP Code:
      class ResultSet {
        private 
      $cache = array(), $pointer = -1$resultSet NULL;
        public function 
      __construct(mysqli_result $resultSet) {
          
      $this->resultSet $resultSet;
        }
        public function 
      fetch_assoc() {
          if(isset(
      $this->cache[++$this->pointer])) return $this->cache[$this->pointer];
          
      $result $this->resultSet->fetch_assoc();
          
      $this->cache[$this->pointer] = $result;
          return 
      $result;
        }
        public function 
      reset() {
          
      $this->pointer = -1;
        }
      }
      $mysql = new mysqli(...)
      $res $mysql->query(...);
      $resultSet = new ResultSet($res);
      while(
      $row $resultSet->fetch_assoc()) {
       ...
      }
      $resultSet->reset(); // now the result set can be iterated over another time 
      dumpfi

      Edit: Huh, never knew that a function like mysql_data_seek() existed.
      Have to study the manual a bit more carefully.
      Last edited by dumpfi; Aug 1, 2005, 05:39 PM.
      "Failure is not an option. It comes bundled with the software."
      ....../)/)..(\__/).(\(\................../)_/)......
      .....(-.-).(='.'=).(-.-)................(o.O)...../<)
      ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
      ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
      Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

      Comment


      • #4
        Neither did I. I just looked at the "See Also" on the mysql_fetch_array() page . You don't need to know everything. You only need to know where to find it.
        I'm not sure if this was any help, but I hope it didn't make you stupider.

        Experience is something you get just after you really need it.
        PHP Installation Guide Feedback welcome.

        Comment


        • #5
          thanks, yeah after I psoted I thought I'd have a look if there were any see alsos on mysql_fetch_array

          Nice function Dumpfi, I really appreciate the effort that went into that
          http://www.hazelryan.co.uk

          Comment

          Working...
          X