我使用的糖Pro的6.1,想知道我怎么可以检索所有的产品,从产品表中其ID。我想有以下code
I am using Sugar Pro 6.1 and want to know that how can i retrieve all the products with their ids from the products table. I am trying with the following code
$sql = "SELECT id, name FROM products order by name";
$result = $GLOBALS["db"]->query($sql);
$products = $GLOBALS["db"]->fetchByAssoc($result);
但它总是只返回第一条记录。
but it always returns only the first record.
是否有可能抓住所有的产品与他们的ID来显示它们在一个HTML下拉列表中,我想,为什么我使用Ajax调用,并在一个单独的PHP文件我用下来的JavaScript文件多数民众赞成以显示该降上述code,返回的输出中的AJAX调用。
Is it possible to grab all the products with their ids to display them in a html dropdown, i want to display that drop down in a javascript file thats why i am using the ajax call and in a seperate php file i am using the above code that returns the ouput to the ajax call.
任何帮助将AP preciated!
Any help will be appreciated!
fetchByAssoc()只抓住一次一个记录。相反,你需要遍历直通调用fetchByAssoc()这样的...
fetchByAssoc() only grabs one record at a time. Instead, you need to iterate thru calling fetchByAssoc() like this...
$sql = "SELECT id, name FROM products order by name";
$result = $GLOBALS["db"]->query($sql);
while ( $product = $GLOBALS["db"]->fetchByAssoc($result) ) {
$products[] = $product;
}