mysql_fetch_array failure?

Thread Solved

Join Date: Mar 2009
Posts: 3
Reputation: naekur is an unknown quantity at this point 
Solved Threads: 0
naekur naekur is offline Offline
Newbie Poster

mysql_fetch_array failure?

 
0
  #1
Mar 4th, 2009
Hi there!

I'm having a very odd problem with mysql_fetch_array my code looks like this:

  1. function getMachines($domain){
  2. if (! is_resource ( $this->connection )) {
  3. return false;
  4. } else {
  5. if (get_magic_quotes_gpc ()) {
  6. $domain = stripslashes ( $domain );
  7. }
  8. $query = sprintf ( "select machines from `domains`.`%s`", $this->escape ( $domain ) );
  9. $result = $this->query ( $query );
  10. if (empty ( $result ) || ! $result) {
  11. return false;
  12. } else {
  13. return $result;
  14. }
  15. }
  16. }
  17.  
  18. $result = getMachines($domain);
  19. echo mysql_num_rows($result);
  20. $row = mysql_fetch_array($result, MYSQL_NUM);

Notes: $this->escape is a shortcut function to mysql_real_escape_string, $this->connection is a private variable holding the sql connection, $this->query is a shortcut to mysql_query.

The problem is that the mysql_num_rows echos out 27, which is correct, but when I do a print_r on $row it only displays only the first item that should be in the select result, and count($row) outputs 1.

Anyone have any ideas? I am using the same basic code other places with no problems.

Thanks!
Last edited by naekur; Mar 4th, 2009 at 4:26 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: mysql_fetch_array failure?

 
0
  #2
Mar 4th, 2009
$result will have a result resource. You need a loop to get all the result. mysql_fetch_array() will fetch only 1 record at a time.
  1. while($row = mysql_fetch_array($result,MYSQL_NUM)) {
  2. print "<pre>";
  3. print_r($row);
  4. print "</pre>";
  5. }
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 3
Reputation: naekur is an unknown quantity at this point 
Solved Threads: 0
naekur naekur is offline Offline
Newbie Poster

Re: mysql_fetch_array failure?

 
0
  #3
Mar 4th, 2009
Thanks! that seems to have fixed it, I guess I misunderstoond how mysql_fetch_array worked.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: mysql_fetch_array failure?

 
0
  #4
Mar 4th, 2009
Cool!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 386 | Replies: 3
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC