Quick question, I am making a class for processing all my db functions, this way it make all my errors uniform and simple...it really helps in debugging

well i have a function query that is called and like it says it processes a query the problem is the class is seperate from the content so if i want lets say all of the rows in a table i have to do a while loop. But I want to put all of the rows into one multideminsion array.

So what can I do to add all the rows to ONE array.

can I just do something along these lines?

$this->data = array()
while(...)
{
  $this->outout = array_push($this->data, $this->row);
}

can i use array_push on other arrays?

    well as i understand it the result of a $query returns all rows as an array called $result

    maybe im totally missing your objective

      Querys return a resource ID that has to be processed either by mysql_fetch_array() or mysql_fetch_assoc()

        yes that will work, but keep in mind that once you return the array into your code, you'll likely have to loop through it again to use it for something. Why not loop through it once normally?

          because the query function is going to be used for tons of things, sometimes tables, sometimes lists, etc, so the output cannot be static all I want is the DATA

            What I do is generate an array, then return a "result" object with that array as an object attribute.

            $data = array();
            while($row = mysql_fetch_assoc($result))
            {
               $data[] = $row;
            }
            return(new QueryResult($data));
            

            And the constructor of QueryResult:

            class QueryResult
            {
               var $data;
               function QueryResult($data);
               {
                  if(is_array($data))
                  {
                     $this->data = $data;
                  }
                  else {
                     user_error("QueryResult::QueryResult(): arg is not an array");
                  }
               }
               // other methods...
            }
            

            You can then reference the result rows by foreach($queryObjName->data), plus my QueryResult class includes methods for outputting the data as table rows or XML.

              thanks that was EXACTLY what i was looking for!

                Write a Reply...