English 中文(简体)
显示阵列的第一部分
原标题:Showing first element of the array

我如何在表格中找到并显示第一个要素的名称?

我猜想,我必须使用像我这样的东西。

$this->data[ lastInvioce ] = $this->Invoice->find( all , array( limit  => 1));

......在控制者发现......

问题回答

你的法典几乎是正确的。 <代码>Model:find(<>/code>的第一个参数表明有多少记录可以检索。 <代码>Model:find(所有)检索所有配对记录。 您想要的是Model:find(先):

// Retrieve most recent Invoice record
$lastInvoice = $this->Invoice->find( first , array(
     fields  => array(  Invoice.name  ),
     order  => array(  Invoice.created  =>  desc  )
);
// Make this Invoice record available in the view
$this->set( compact( lastInvoice ));

这将检索最近创建的<代码>Invoice记录,仅检索 姓名/编码>领域。 <代码>$this->set()中的数据可在您看来查阅。 因此:

echo $lastInvoice[ Invoice ][ name ];

或者说:

extract($lastInvoice);
echo $Invoice[ name ];

Try $this->Invoice->find(首次,......)。 当然,你可以利用其他条件和(或)进行操纵。





相关问题
Search field with Thickbox issue

i have a search form which is shown with Thickbox inside an iframe. the problem is.. that after i click "search" the result page is shown inside the same iframe! and i want it to be shown in the main ...

Will an incomplete google sitemap hurt my search ranking?

If I submit a sitemap.xml which does not contain all of the pages of my site, will this affect my search ranking? For example: If my sitemap only contained pages that had been created in the last ...

speeding up windows file search with C#

i made a program that search logical drives to find a specific file .if user type file name an click search button , searching begins , but i don t know how to stop searching in the middle of process....

JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

Embed Google/ Yahoo search into a web site or build your own

I am looking for an opinion on the whether to use Google custom search, Yahoo search builder or build my own for web projects (no more than 100 pages of content). If I should build my own - do you ...

热门标签