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 Link to comment https://forums.phpfreaks.com/topic/61267-solved-query-working-solonot-in-a-while-loop/ 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. Link to comment https://forums.phpfreaks.com/topic/61267-solved-query-working-solonot-in-a-while-loop/#findComment-304857 Share on other sites More sharing options...
AbydosGater Posted July 22, 2007 Author Share Posted July 22, 2007 Ahhhhh Sorry didnt see that! Thanks Link to comment https://forums.phpfreaks.com/topic/61267-solved-query-working-solonot-in-a-while-loop/#findComment-304880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.