嗨很多天我一直在研究MySQL中的这个问题,但我无法弄明白.你们有什么建议吗?
基本上,我有一个类别表,其域名包括:id,name(类别名称)和parent(类别的父ID).
示例数据:
1 Fruit 0
2 Apple 1
3 pear 1
4 FujiApple 2
5 AusApple 2
6 SydneyAPPLE 5
....
Run Code Online (Sandbox Code Playgroud)
有许多级别,可能超过3个级别.我想创建一个sql查询,根据他的层次结构对数据进行分组:parent> child> grandchild>等.
它应该输出树结构,如下所示:
1 Fruit 0
^ 2 Apple 1
^ 4 FujiApple 2
- 5 AusApple 2
^ 6 SydneyApple 5
- 3 pear 1
Run Code Online (Sandbox Code Playgroud)
我可以使用单个SQL查询执行此操作吗?我尝试过并且确实有效的替代方案如下:
SELECT * FROM category WHERE parent=0
Run Code Online (Sandbox Code Playgroud)
在此之后,我再次遍历数据,并选择parent = id的行.这似乎是一个糟糕的解决方案.因为它是mySQL,所以不能使用CTE.
在Prototype中,是否有AJAX启动/停止事件,允许您创建一个脚本,以便在AJAX加载期间全局显示模态等待消息?
就像,使用jQuery我在应用程序布局中使用这个脚本来全局显示任何jQuery AJAX事件的模态等待对话框:
<script type="text/javascript">
$(document).ajaxStart(function () {
$.blockUI({ message: '<h1><img src="../images/busy.gif" /> Just a moment...</h1>' });
});
$(document).ajaxStop(function () {
$.unblockUI();
});
</script>
Run Code Online (Sandbox Code Playgroud)
谢谢 - 非常感谢?
我试图将一个外键添加到表中,它给我以下错误:
引用表'tbl_Person'中没有主键或候选键与外键'P_ID'中的引用列列表匹配.
我有一个tbl_Person,定义为:
P_ID INT (Primary Key)
f_Name,
l_Name
Run Code Online (Sandbox Code Playgroud)
另一个表是一个注释表,定义如下:
C_ID INT,
Comments,
P_ID (should be the foreign key)
Run Code Online (Sandbox Code Playgroud)
尝试创建一对多关系表,因此当用户添加注释时,它会被引用给他,同时,他可以在不初始化新注释的情况下添加到注释中.希望这有点意义.
例如:Randy Bing输入"我喜欢SQL",他的ID是1,f_Name是Randy,l_Name是Bing,他的评论是"我喜欢Sql".他的评论应该存储一个唯一的ID,并导入他的P_ID.
稍后当Randy想要使用与P_ID匹配的相同C_ID添加注释而不创建新的C_ID.
这是代码:
ALTER TABLE tbl_Comments
ADD CONSTRAINT P_ID
FOREIGN KEY (P_ID)
REFERENCES tbl_Person(P_ID)
Run Code Online (Sandbox Code Playgroud)
我接近正确的轨道吗?
我只是想了解MSDeploy的C#API(Microsoft.Web.Deployment.dll),但是我正在努力寻找一种确定给定Web服务器依赖性的方法。
基本上,我希望使用等效于以下MSDeploy命令行调用的C#:
msdeploy.exe -verb:getDependencies -source:webServer
Run Code Online (Sandbox Code Playgroud)
我已经尝试过文档,但是没有运气。有人能指出我正确的方向吗?
我有一个场景,我需要从数据库中提取数据并将其写为xml.问题是用户希望每个元素(DB列)用新行分隔.我正在提取的db表有大约20,000行,并且有很多ntext列(表大小约为3 Gig).
我将文件分成250行,每个文件大约每个14MB.问题是解析真的很慢.为了在每个元素/列之间添加一个新行,我在db中出来的每一列之间添加了一些唯一的字符串,这样我就可以使用Regex.Split函数并为该数组中的每个项添加一个新行.
我确信缓慢是我的用户错误/无知,因为我主要生活在数据库中,但我不知道该怎么做才能尝试加快解析速度.从数据库中提取数据作为xml的速度非常快,写入速度相当快.但是,引入解析并在每个元素之间添加新行使每个文件每个文件写入大约3分钟.
任何关于我应该在C#中使用什么来解析和添加换行的建议都将非常感激.
我一如既往地感谢Stack上的输入/评论.
我用来解析xml数据的代码:
//parsing the xml anywhere I see the string AddNewLine
public static void WriteFile(string xml,int fileNum)
{
string[] xmlArray = Regex.Split(xml, "AddNewLine");
string newXml = "";
//Getting filepath to write file out to
Connection filePath = new Connection();
string fileName = filePath.FilePath;
//foreach item in the array append carriage and new line
foreach(string xmlRow in xmlArray)
{
newXml = newXml + xmlRow + "\n\r\n";
}
//use StreamWriter to write file
using (StreamWriter sw = …Run Code Online (Sandbox Code Playgroud) 也许我的设计不好,但我正在尝试为小型商店启动和运行订购系统.由于它是礼品订单,因此可以让发件人和收件人显示订单的来往地点.
所以我们有桌子
Person
personid
name
address
Order
Sender_personid
Receiver_personid
etc...
Run Code Online (Sandbox Code Playgroud)
我无法创建一个sql语句来选择订单中两个人的姓名和地址.如果可以做到这一点,任何指针都会很棒.如果没有任何设计指针同样apreciated.
我想要一段不涉及循环但自动生成一些C++代码的代码.
我有一个const int d,从这里我想编写d行代码来访问一个数组.所以举个例子
for(int k=0; k<d;++k){
// do something to myarryay[k];
}
Run Code Online (Sandbox Code Playgroud)
但我不想在for循环中写这个.我希望编译器执行,就好像编写了以下代码行:
do something to myarray[0]
do something to myarray[1]
.
.
.
do something to myarray[d]
Run Code Online (Sandbox Code Playgroud)
任何人都可以给我一些建议吗?
提前致谢.
我想知道如何限制应用程序窗口只按比例调整大小?我希望它保持比例,以免扭曲照片/视频.
拥有JSF 1.2两个页面(one.xhtml和other.xhtml),
它们按照以下规则包含在当前页面中:
...
<c:if test="#{flowScope.Bean.param1}">
<ui:include src="one.xhtml"/>
</c:if>
<c:if test="#{!flowScope.Bean.param1}">
<ui:include src="other.xhtml"/>
</c:if>
...
Run Code Online (Sandbox Code Playgroud)
据one.xhtml不同于other.xhtml只能通过动作参数:
one.xhtml:<h:commandLink action="actionOne">
other.xhtml:<h:commandLink action="actionTwo">
是否可以使用一些通用的xhtml?
而不是one.xhtml和other.xhtml,这样的事情:
...
<c:if test="#{flowScope.Bean.param1}">
<ui:include src="general.xhtml" param="actionOne"/>
</c:if>
<c:if test="#{!flowScope.Bean.param1}">
<ui:include src="general.xhtml" param="actionTwo"/>
</c:if>
...
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.