$rs = $cmd->ExecuteReader("SELECT * FROM products LIMIT 0,10");
while ($rs->Read())
{
echo "<li>".$rs->GetData("name")."</li>";
}我想取出数据集中的所有记录,但这样写总是第一条记录没有显示出来,怎样写才能显示所有的记录呢?
while ($rs->Read())
{
echo "<li>".$rs->GetData("name")."</li>";
}我想取出数据集中的所有记录,但这样写总是第一条记录没有显示出来,怎样写才能显示所有的记录呢?
<?php
class MyReader
{
var $rows;
var $current;
var $data; function MyReader()
{
$this->rows = 0;
$this->current = -1;
$this->data = "";
} function IsEof()
{
if ($this->current >= $this->rows)
return true;
else
return false;
} function Read()
{
$this->current++; if ($this->current < $this->rows)
return true;
else
return false;
} function Move($num)
{
$this->current = $this->current+$num; if ($this->current < $this->rows)
return true;
else
return false;
} function GetData($name)
{
return $this->data[$this->current][$name];
}
}
?><?php
@include("myreader.php");class MyCommand
{
var $id;
var $host;
var $user;
var $pass;
var $db; function MyCommand($hostname,$username,$password,$dbname)
{
$this->host = $hostname;
$this->user = $username;
$this->pass = $password;
$this->db = $dbname;
} function Open()
{
$this->id = @mysql_connect($this->host,$this->user,$this->pass) or
die("无法连接数据库");
@mysql_select_db($this->db,$this->id) or
die("选择数据库失败");
} function Close()
{
@mysql_close($this->id);
} function ExecuteQuery($sql)
{
$result = @mysql_query($sql,$this->id) or
die("无法执行查询:".$sql); return $result;
} function ExecuteNonQuery($sql)
{
$result = $this->ExecuteQuery($sql);
} function ExecuteInsert($sql)
{
$result = $this->ExecuteQuery($sql);
$insertid = @mysql_insert_id();
return $insertid;
} function ExecuteReader($sql)
{
$result = $this->ExecuteQuery($sql);
$reader = new MyReader();
$i=0; while ($arr = mysql_fetch_array($result))
{
$reader->data[$i] = $arr;
$i++;
}
$reader->rows = @mysql_num_rows($result); return $reader;
}
}
?>
do{
echo "<li>".$rs->GetData("name")."</li>";
}while ($rs->Read());
即可!
if(empty($rs->GetData("name")){
continue;
}
echo "<li>".$rs->GetData("name")."</li>";
}while ($rs->Read());
如果是一个数组 可以reset() 数据库没有你所谓的第一条数据那就没办法了