| | |
mysql_fetch_array failure?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2009
Posts: 3
Reputation:
Solved Threads: 0
Hi there!
I'm having a very odd problem with mysql_fetch_array my code looks like this:
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!
I'm having a very odd problem with mysql_fetch_array my code looks like this:
PHP Syntax (Toggle Plain Text)
function getMachines($domain){ if (! is_resource ( $this->connection )) { return false; } else { if (get_magic_quotes_gpc ()) { $domain = stripslashes ( $domain ); } $query = sprintf ( "select machines from `domains`.`%s`", $this->escape ( $domain ) ); $result = $this->query ( $query ); if (empty ( $result ) || ! $result) { return false; } else { return $result; } } } $result = getMachines($domain); echo mysql_num_rows($result); $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.
$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.
php Syntax (Toggle Plain Text)
while($row = mysql_fetch_array($result,MYSQL_NUM)) { print "<pre>"; print_r($row); print "</pre>"; }
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- Insert multiple checkbox values of array into mysql db (PHP)
- Onclick show ondblclk hide (PHP)
- Script for voting (PHP)
- Displaying data from database (PHP)
- Email code problem (PHP)
- Changes made in Admin side sholut be shown in Client page?? (PHP)
- paging related i have got this error Warning: mysql_fetch_array(): supplied argument (PHP)
- problems with sessions and login.php (PHP)
Other Threads in the PHP Forum
- Previous Thread: Help! my script couldn't submit form data to mysql database
- Next Thread: Restarting Apps Using Php
Views: 386 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date datepart directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link list login loop mail menu methods mlm mod_rewrite multiple mysql oop parse password paypal pdf php problem query radio random recursion regex remote script search select seo server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web webdesign xml youtube






Cool! 