Adam Posted November 2, 2008 Share Posted November 2, 2008 I'm trying to setup my own db class, but have a problem with the "fetchRow" function. The query is being executed fine and this method does return part of the result but only the first field :S Been looking at this for a while and can't work it out... public function fetchRow() { if ($this->rowCount() == 0) return false; if (@$this->result = mysql_result($this->query, $this->row_id)) { $this->row_id++; return $this->result; } else { $this->row_id = 0; return false; } return true; } It's called in this way: while ($row = $db->fetchRow()) { print_r($row); } Can anybody spot the problem :S Cheers for any help! Adam[/code] Quote Link to comment https://forums.phpfreaks.com/topic/131119-problem-with-fetchrow-function/ Share on other sites More sharing options...
Adam Posted November 2, 2008 Author Share Posted November 2, 2008 Hah I've come to realise that mysql_result only returns one field from the row. But looking and I can't find another function that returns a whole row at a given row number? Like say: mysql_fetch_assoc($query, $rowNum); anybody know of one?? Cheers. Adam! Quote Link to comment https://forums.phpfreaks.com/topic/131119-problem-with-fetchrow-function/#findComment-680771 Share on other sites More sharing options...
corbin Posted November 2, 2008 Share Posted November 2, 2008 mysql_result isn't often used.... Why not just do: public function fetchRow() { return mysql_fetch_row($this->query); } while($row = $db->fetchRow()) { } Quote Link to comment https://forums.phpfreaks.com/topic/131119-problem-with-fetchrow-function/#findComment-680778 Share on other sites More sharing options...
maxudaskin Posted November 2, 2008 Share Posted November 2, 2008 while($row = mysql_fetch_array($query)) { // Do whatever } mysql_fetch_array Quote Link to comment https://forums.phpfreaks.com/topic/131119-problem-with-fetchrow-function/#findComment-680781 Share on other sites More sharing options...
Adam Posted November 2, 2008 Author Share Posted November 2, 2008 maxudaskin: while($row = mysql_fetch_array($query)) { // Do whatever } I'm trying to create a db handler class, using the standard functions would kind of defeat the point.. corbin: Ahh I wasn't aware the mysql_fetch_row function would return the next row every time it's called.. Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/131119-problem-with-fetchrow-function/#findComment-680810 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.