fimi
01-22-2004, 04:12 PM
i've made a database class and when i call the sql_array() function in the class it gives me the array but when i try to print
the data in the array it prints an infinite loop and nothing else.
i tested sql_numrows() tells me that there are 9 records in that table.
i don't understand why its not working!
here's the code.
<?
$test = new query("select * from [TABLE]");
$numrows = $test->sql_numrows();
echo "<br>how many records found: $numrows<br>";
while ($row = $test->sql_array()){
echo "-field A: ".$row['a_field']."<br>";
}
class query{
var $server;
var $db;
var $user;
var $password ;
var $error;
var $query;
function query($value){
//initialize variables
$this->server = "localhost";
$this->db = "adatabse";
$this->user = "ausername";
$this->password = "apassword";
$this->query = $value;
//connect to server and select database
$db_con = @mysql_connect($this->server,$this->user,$this->password) or die( $this->error = "Database connection failure!");
$db_sel = @mysql_select_db($this->db) or die ( $this->error ="Could not connect to specified database, db may not exist");
//check if errors occured.
if (!$db_con){
echo $this->error;
exit;
}elseif (!$db_sel){
echo $this->error ;
exit;
}
}
function sql_query(){
//exec query...
$sql_result = mysql_query($this->query) or die($this->error ="Error: <b>".mysql_error()."</b>.");
//if any errors occur?
if(!$result_sql){
echo $this->error;
exit;
}else{
return $result_sql;
}
}function sql_array(){
$sql_result = mysql_query($this->query);
$sql_arrays = mysql_fetch_array($sql_result);
return ($sql_arrays);
}function sql_numrows(){
$sql_result = mysql_query($this->query) or die($this->error ="Error: <b>".mysql_error()."</b>.");
$sql_numrows = mysql_num_rows($sql_result);
return $sql_numrows;
}
}
?>
output
how many records found: 9
-field A:
-field A:
-field A:
-field A:
-field A:
........ and so on
forum search!( mysql_fetch_array , infinte loop, while infinite)
the data in the array it prints an infinite loop and nothing else.
i tested sql_numrows() tells me that there are 9 records in that table.
i don't understand why its not working!
here's the code.
<?
$test = new query("select * from [TABLE]");
$numrows = $test->sql_numrows();
echo "<br>how many records found: $numrows<br>";
while ($row = $test->sql_array()){
echo "-field A: ".$row['a_field']."<br>";
}
class query{
var $server;
var $db;
var $user;
var $password ;
var $error;
var $query;
function query($value){
//initialize variables
$this->server = "localhost";
$this->db = "adatabse";
$this->user = "ausername";
$this->password = "apassword";
$this->query = $value;
//connect to server and select database
$db_con = @mysql_connect($this->server,$this->user,$this->password) or die( $this->error = "Database connection failure!");
$db_sel = @mysql_select_db($this->db) or die ( $this->error ="Could not connect to specified database, db may not exist");
//check if errors occured.
if (!$db_con){
echo $this->error;
exit;
}elseif (!$db_sel){
echo $this->error ;
exit;
}
}
function sql_query(){
//exec query...
$sql_result = mysql_query($this->query) or die($this->error ="Error: <b>".mysql_error()."</b>.");
//if any errors occur?
if(!$result_sql){
echo $this->error;
exit;
}else{
return $result_sql;
}
}function sql_array(){
$sql_result = mysql_query($this->query);
$sql_arrays = mysql_fetch_array($sql_result);
return ($sql_arrays);
}function sql_numrows(){
$sql_result = mysql_query($this->query) or die($this->error ="Error: <b>".mysql_error()."</b>.");
$sql_numrows = mysql_num_rows($sql_result);
return $sql_numrows;
}
}
?>
output
how many records found: 9
-field A:
-field A:
-field A:
-field A:
-field A:
........ and so on
forum search!( mysql_fetch_array , infinte loop, while infinite)