poirot Posted April 22, 2006 Share Posted April 22, 2006 OK, I here it goes. I have a class to handle the MySQL database, it's something like the class at the bottom. I thought it worked, until...[code]$sql = new Database; // Initializing class$sql->connect(); // Connects to the database.$sql->result = $sql->query("SELECT * FROM `table`"); // Sample Querywhile ($row = $sql->fetch()) { echo $row['field1'] . $row['field3']; // <<< The problem}[/code]But for some reason, it wll only echo the first result! Even when the query returns more than 1 row, it will echo/display the first one!Any Ideas?Class:[code]class Database{ var $result // This is the result resource; function query($query) { $return = mysql_query($query) or $this->error_handle(mysql_error(), mysql_errno()); // basic error handling function return $return; } // Shorthand fetching; fetch_assoc as default function fetch($mode='assoc') { switch ($mode) { case 'array': $ret = mysql_fetch_array($this->result); break; case 'row': $ret = mysql_fetch_row($this->result); break; default: $ret = mysql_fetch_assoc($this->result); } return $ret; }}[/code]Thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/8100-problem-with-mysq_fetch_-classes/ Share on other sites More sharing options...
Ninjakreborn Posted April 22, 2006 Share Posted April 22, 2006 maybe that . in the middle of the rows is supposed to be something else.or maybe something could be wrong with the database, meaning maybe the row in the database isn't connecting right.just some guesses as I don't know databasing quite yet.[a href=\"http://www.php-scripts.com/php_diary/070700.php3\" target=\"_blank\"]http://www.php-scripts.com/php_diary/070700.php3[/a]maybe this can help some, you know more about php and mysql than me, I don't know what to make of it, but I looked at your problem and ran through google, maybe that will help some. Quote Link to comment https://forums.phpfreaks.com/topic/8100-problem-with-mysq_fetch_-classes/#findComment-29530 Share on other sites More sharing options...
poirot Posted April 22, 2006 Author Share Posted April 22, 2006 Oh no, if I do it (same script, same query, same database) using the "classic" method:[code]$result = mysql_query("SELECT * FROM `table`");while ($row = mysql_fetch_assoc($result)) { echo $row['field1'] . $row['field3']; // <<< The problem}[/code]It just works fine. Quote Link to comment https://forums.phpfreaks.com/topic/8100-problem-with-mysq_fetch_-classes/#findComment-29534 Share on other sites More sharing options...
Ninjakreborn Posted April 22, 2006 Share Posted April 22, 2006 why don't you use the classic method this time, maybe one of the things you are trying to do with the other method you are not used to and maybe doing it wrong, is there a reason you don't want to go with your normal way. Quote Link to comment https://forums.phpfreaks.com/topic/8100-problem-with-mysq_fetch_-classes/#findComment-29535 Share on other sites More sharing options...
poirot Posted April 22, 2006 Author Share Posted April 22, 2006 [!--quoteo(post=367399:date=Apr 21 2006, 07:02 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 21 2006, 07:02 PM) [snapback]367399[/snapback][/div][div class=\'quotemain\'][!--quotec--]why don't you use the classic method this time, maybe one of the things you are trying to do with the other method you are not used to and maybe doing it wrong, is there a reason you don't want to go with your normal way.[/quote]I prefer the class because OOP makes things more organized. Besides, I have some debug and error handling functions that I don't want to call every time I call a query. Quote Link to comment https://forums.phpfreaks.com/topic/8100-problem-with-mysq_fetch_-classes/#findComment-29540 Share on other sites More sharing options...
Ninjakreborn Posted April 22, 2006 Share Posted April 22, 2006 This might not help you much but if you are using php5 I know of a site that has the completely new system I read that the php object oriented programming entire system was redesigned here is a link, but I cna't help other than that, because I stopped studying tonight and haven't gotten into oop yet, I was starting that actually monday I just told my host to switch over my server to php5 it takes them 4 hours.[a href=\"http://www.hudzilla.org/phpbook/read.php/6_0_0\" target=\"_blank\"]http://www.hudzilla.org/phpbook/read.php/6_0_0[/a]see if you can find something there real quick, theres a section there on mysql databases too in case if that one I gave you doens't help. Quote Link to comment https://forums.phpfreaks.com/topic/8100-problem-with-mysq_fetch_-classes/#findComment-29541 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.