[英]SQL / PHP - only display the first value of my database
All is in the title. 全部都在标题中。 why I only get the first line of my table and not all the fields.
为什么我只得到表格的第一行而不是所有字段。
Function : 功能说明
class Services_Label extends Services_Abstract
{
public function getlibelle()
{
$sRequest = 'SELECT NAME FROM menu WHERE id_application = 2';
$this->executeQueries($sRequest);
$aResult = $this->getOneResult();
$this->freeStatement();
return $aResult;
}
}
function application : 功能应用:
$oMessage = new Services_Label();
$toto = $oMessage->getlibelle();
var_dump($toto);
answer : 答:
string(15) "Prise en charge"
Going by the name of the getOneResult()
, your resultset is probably being limited to one result. 按照
getOneResult()
的名称,您的结果集可能仅限于一个结果。
Can you post the whole function to confirm? 您可以发布整个功能进行确认吗?
I have no idea from your question what your table columns are called, but if you want all of the columns use SELECT *
我不知道您的问题是什么叫您的表列,但如果您想所有的列使用
SELECT *
class Services_Label extends Services_Abstract
{
public function getlibelle()
{
$sRequest = 'SELECT * FROM menu WHERE id_application = 2';
$this->executeQueries($sRequest);
$aResult = $this->getOneResult();
$this->freeStatement();
return $aResult;
}
}
It is most often better to actually name only the columns you actually want returned so you would do that like this 通常最好只实际命名您实际想要返回的列,这样您就可以这样做
class Services_Label extends Services_Abstract
{
public function getlibelle()
{
$sRequest = 'SELECT NAME,COL2,COL3 FROM menu WHERE id_application = 2';
$this->executeQueries($sRequest);
$aResult = $this->getOneResult();
$this->freeStatement();
return $aResult;
}
}
this is the function getoneresult() 这是功能getoneresult()
public function getOneResult()
{
$row = $this->getNextRow(OCI_BOTH | OCI_RETURN_NULLS);
if (is_array($row)) {
return $row[0];
} else {
return false;
}
}
You need to collect the rows using a while loop. 您需要使用while循环来收集行。 So change your function 'getOneResult' to something like this.
因此,将函数“ getOneResult”更改为类似的内容。
public function getResults()
{
$array = array();
while ($row = $this->getNextRow(OCI_BOTH | OCI_RETURN_NULLS)) {
$array[] = $row;
}
return $array;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.