从OpenCart中按类别检索产品(Retrieve Products By Category from OpenCart)
如何编写一个PHP代码片段来读取OpenCart数据库以按类别提取产品并将其显示在OpenCart框架之外? 举例来说,我为小部件A和B构建了这个漂亮的前端网站,但是之后安装了一个名为/ cart的子目录,其中安装了OpenCart,并在我的前端网站中加载了某种OpenCart库文件,然后读取数据库以获取产品按类别(A和B)。 或者,也许你知道直接SQL本身的技术?
这个问题不同于这个问题,因为我试图不在OpenCart中构建新模板,而是使用API(或直接访问数据库)在OpenCart的应用程序框架之外和我自己的应用程序框架中显示产品。
How do I write a PHP snippet to read an OpenCart database to pull products by category and display it outside of an OpenCart framework? So for instance, I build this nice frontend website for widgets A and B, but then have a subdir called /cart where OpenCart is installed, and in my frontend website I load some kind of OpenCart library file and then read the database to get products by category (A and B). Or, perhaps you know the technique with direct SQL itself?
This question is different than this one because I'm trying to not build a new template in OpenCart, but use an API (or go direct to the database) to show products outside of OpenCart's application framework and in my own application framework.
原文:https://stackoverflow.com/questions/42685929
最满意答案
你的代码不起作用的原因是因为你的循环是:
for (var i = 0; i <= folderList.Count; i++)
...其中
folderList
是Folder_Settings
元素的列表。 只有其中一个,所以你要迭代两次。 你实际上并没有使用folderList[i]
,这是一个很好的工作,因为否则你将在第二次迭代中超出范围。 这样的循环应该总是使用<
而不是<=
。但是,我强烈建议使用LINQ to XML而不是
XmlDocument
- 它使一切变得更加简单。 我也建议你尽可能使用foreach
循环:var doc = XDocument.Load("Settings.xml"); foreach (var element in doc.Root.Elements("OtherFolderSettings)) { listBox1.Items.Add(element.Value); }
(哦,并使用语句来干净地关闭资源......)
The reason your code isn't working is because your loop is:
for (var i = 0; i <= folderList.Count; i++)
... where
folderList
is the list ofFolder_Settings
elements. There's only one of those, so you're iterating twice. It's a good job you don't actually usefolderList[i]
, because otherwise you'd be out of bounds on the second iteration. Loops like that should pretty much always use<
rather than<=
.However, I would strongly recommend using LINQ to XML instead of
XmlDocument
- it makes everything much simpler. I'd also recommend usingforeach
loops whenever you can, too:var doc = XDocument.Load("Settings.xml"); foreach (var element in doc.Root.Elements("OtherFolderSettings)) { listBox1.Items.Add(element.Value); }
(Oh, and use
using
statements to close resources cleanly...)
相关问答
更多-
ListBox没有列的概念,所以我想你想在其中显示简单的字符串行。 然后你可以简单地将字符串添加到Items集合中: public PatientList() { InitializeComponent(); HumanResources ListAllPatients = new HumanResources(); List
AllPatients = ListAllPatients.PopPatien ... -
尝试更改将Destination填充到的查询 Destination = c.Descendants("destination") .Select(e => e.Value) .Where(s => !string.IsNullOrEmpty(s)) .ToList(); 这将使用List填充它,然后您可以将其绑定到您的控件。 Trying changing your query which populates De ...
-
从ListBox更新XML LINQ(Update XML LINQ from ListBox)[2022-09-16]
我会逐步执行您的代码,以确保它循环遍历每个文件。 还要仔细检查并确保将“s”设置为正确的文件。 如果它循环遍历每个文件并成功调用“SetElementValue”,则可能与必须为“foreach”中的每个循环检索“filesToProcess”节点有关。 而不是你拥有的,试试这个: // Now add the elements from the listbox var filesToProcessNode = uElem.Element("filestoProcess"); foreach (string ... -
用SQL填充列表框(Populating listbox with SQL)[2023-09-18]
你的问题是列表框没有.recordsource它有一个行来源 Your problem is that a list box does not have a .recordsource It has a RowSource -
通过@ fhdrsdg的评论,您将了解如何实现您的结果。您将使用set获取值,然后loop遍历变量unique以插入到Listbox 。 from tkinter import * rows = (('python', 'kivy'), ('python', 'tkinter'),("python","wxpython",32), ('PHP', 'bootstrap'),('html', 'ajax'),('html', 'css') ) root = Tk() l = Listbox(root) ...
-
每次我做过这个,我都使用RowSource作为列表框,在第一个列表框的OnChange事件中,我构造了一个SQL字符串并更新了第二个列表框的RowSource。 就像是: sSQL = "SELECT * FROM MyTable WHERE MyField = " & forms![HHRRR]![List0].Text & "" Me.Listbox2.RowSource = sSQL Me.Listbox2.Requery 这完全是“空中代码”,可能需要一些调整,但你明白了。 Any time I' ...
-
你的代码不起作用的原因是因为你的循环是: for (var i = 0; i <= folderList.Count; i++) ...其中folderList是Folder_Settings元素的列表。 只有其中一个,所以你要迭代两次。 你实际上并没有使用folderList[i] ,这是一个很好的工作,因为否则你将在第二次迭代中超出范围。 这样的循环应该总是使用<而不是<= 。 但是,我强烈建议使用LINQ to XML而不是XmlDocument - 它使一切变得更加简单。 我也建议你尽可能使用fo ...
-
填充列表框(populating listbox)[2022-07-19]
var records = from line in File.ReadAllLines(@"D:\file.txt") let parts = line.Split(';') select new { Company = parts[0], Identification = parts[2] }; listBox1.Dat ... -
您还必须指定: lstDepartment.DataSource = oCorp.GetEmployeeList(emp); lstDepartment.DataTextField = "EmployeeID"; lstDepartment.DataValueField = "EmployeeID"; lstDepartment.DataBind() You have to also specify this: lstDepartment.DataSour ...
-
1.如果使用MVVM模式 :在viewModel中实现INotifyPropertyChanged并声明: private ObservableCollection
_posts; public ObservableCollection Posts { get{return _posts;} set { _posts = value; RaisePropertyChanged("Posts"); } } 在x ...