If you want to use foreach on a mysql_query result you'll have to implement an iterator. For example:
class MySQLResultIterator implements Iterator
{
private $result;
private $current;
private $pos = 0;
public function __construct($result)
{
$this->result = $result;
$this->updateCurrent();
}
public function rewind() {
mysql_data_seek($this->result, 0);
$this->pos = 0;
$this->updateCurrent();
}
public function current() {
return $this->current;
}
public function key() {
return $this->pos;
}
public function next() {
$this->updateCurrent();
$this->pos++;
return $this->current;
}
public function valid() {
return ($this->current != false);
}
private function updateCurrent() {
$this->current = mysql_fetch_assoc($this->result);
}
}
$data = mysql_query("SELECT * FROM a2h_member_type") or die(mysql_error());
$iterator = new MySQLResultIterator($data);
foreach( $iterator as $row )
{
// ...
}