AbydosGater Posted July 22, 2007 Share Posted July 22, 2007 Hey Guys, Im redoing my config class for my site, The __construct() is basicly just selects each row of the config table and saves it to the $this->data[] array.. function __construct(){ global $sql; $temp = $sql->_query(" SELECT * FROM sb_config ORDER BY `sb_config`.`key` "); while($temp = $sql->_fetch_assoc($temp)){ $this->data[] = $temp; } define('URL', $this->data['domain'].$this->data['path']); } The database is basicly just: Key -- Value.. IE: domain -- localhost Now if i run that code.. I get a "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource".. But if i take out the loop and use: function __construct(){ global $sql; $temp = $sql->_query(" SELECT * FROM sb_config ORDER BY `sb_config`.`key` "); $temp = $sql->_fetch_assoc($temp); print_r($temp); } That works fine.. selects the first row..and it is a valid resource.. But why is it not working with the loop? Andy Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 22, 2007 Share Posted July 22, 2007 Change $temp to a different variable for your while, eg: function __construct(){ global $sql; $temp = $sql->_query(" SELECT * FROM sb_config ORDER BY `sb_config`.`key` "); while($row = $sql->_fetch_assoc($temp)){ $this->data[] = $row; } define('URL', $this->data['domain'].$this->data['path']); } When you use $temp = $sql->_fetch_assoc($temp). You are overwriting the temp variable which then losses the result resource for the query and thus you are getting the error you getting. Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted July 22, 2007 Author Share Posted July 22, 2007 Ahhhhh Sorry didnt see that! Thanks Quote Link to comment 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.