使用PHP进行精确值搜索(Exact value search with PHP)
我正在使用以下代码来搜索生成的表并过滤数据。 我的问题是,当我搜索让我们说
1
,它不会搜索和过滤仅1
而是包含1
的数据,如11, 21, etc.
。如何搜索并过滤我输入的确切数据?
<?php if(isset($_POST['search'])) { $valueToSearch = $_POST['valueToSearch']; // search in all table columns // using concat mysql function $query = "SELECT * FROM `tbstats` WHERE CONCAT(`date`, `mode`, `svar`, `sdev`) LIKE '%".$valueToSearch."%'"; $search_result = filterTable($query); } else { $query = "SELECT * FROM `tbstats`"; $search_result = filterTable($query); } function filterTable($query) { $connect = mysqli_connect("localhost", "root", "", "dbstats"); $filter_Result = mysqli_query($connect, $query); return $filter_Result; } ?> <!DOCTYPE html> <html> <head> <title>Stats</title> <style> table,tr,th,td { border: 1px solid black; } </style> </head> <body> <form action="stats_filter.php" method="post"> <input type="text" name="valueToSearch" placeholder="Value To Search"><br><br> <input type="submit" name="search" value="Filter"><br><br> <table> <tr> <th>Date</th> <th>Mode</th> <th>Svar</th> <th>Sdev</th> </tr> <?php while($row = mysqli_fetch_array($search_result)):?> <tr> <td><?php echo $row['date'];?></td> <td><?php echo $row['mode'];?></td> <td><?php echo $row['svar'];?></td> <td><?php echo $row['sdev'];?></td> </tr> <?php endwhile;?> </table> </form> </body> </html>
I'm using the following code to search the generated table and filter data. My problem is that when I search for lets say
1
, it doesn't search & filter only1
but also the data containing1
like11, 21, etc.
.How can I make it search and filter the exact data I enter?
<?php if(isset($_POST['search'])) { $valueToSearch = $_POST['valueToSearch']; // search in all table columns // using concat mysql function $query = "SELECT * FROM `tbstats` WHERE CONCAT(`date`, `mode`, `svar`, `sdev`) LIKE '%".$valueToSearch."%'"; $search_result = filterTable($query); } else { $query = "SELECT * FROM `tbstats`"; $search_result = filterTable($query); } function filterTable($query) { $connect = mysqli_connect("localhost", "root", "", "dbstats"); $filter_Result = mysqli_query($connect, $query); return $filter_Result; } ?> <!DOCTYPE html> <html> <head> <title>Stats</title> <style> table,tr,th,td { border: 1px solid black; } </style> </head> <body> <form action="stats_filter.php" method="post"> <input type="text" name="valueToSearch" placeholder="Value To Search"><br><br> <input type="submit" name="search" value="Filter"><br><br> <table> <tr> <th>Date</th> <th>Mode</th> <th>Svar</th> <th>Sdev</th> </tr> <?php while($row = mysqli_fetch_array($search_result)):?> <tr> <td><?php echo $row['date'];?></td> <td><?php echo $row['mode'];?></td> <td><?php echo $row['svar'];?></td> <td><?php echo $row['sdev'];?></td> </tr> <?php endwhile;?> </table> </form> </body> </html>
原文:https://stackoverflow.com/questions/51443382
最满意答案
我想删除使用LibGit2Sharp从远程存储库克隆的本地repo文件夹。 我在这里读到,我必须在删除之前Dispose()存储库。
LibGit2Sharp保持.git文件夹中的一些文件(主要是出于性能原因的包文件)。 调用
Dispose()
将释放这些句柄并释放非托管内存。因此,依赖
using
语句确实是一个强烈的建议(或者,至少在完成时使用Dispose()
存储库实例)。如果你不这样做,那么当你的AppDomain卸载时,这些句柄最终将通过终结器发布,但是你将不能真正控制将要发生的“何时”。
编辑:再次读你的代码,我忽略了一些东西。 推荐的模式是
using (var repo = new LibGit2Sharp.Repository(path)) { // Do amazing stuff }
要么
var repo = new LibGit2Sharp.Repository(path); // Do amazing stuff repo.Dispose();
事实上,一旦代码到达作用域的末尾,
using
语句将自动发出对Dispose()
的调用。访问路径'c16566a7-202a-4c8a-84de-3e3caadd5af9'被拒绝。
关于这一点,我认为这与LibGit2Sharp无关。
这个过程(试图删除以guid命名的文件夹)在授予足够权限的身份下运行?
I would like to delete the local repo folder that I cloned from remote repository using LibGit2Sharp. I read here here that I have to Dispose() the Repository before I can delete it.
LibGit2Sharp keeps hold on some files in the .git folder (mainly the packfiles for performance reasons). Calling
Dispose()
will release those handles and deallocate the non managed memory.As such, it's indeed a strong recommendation to rely on the
using
statement (or, at the very least toDispose()
the Repository instance when you're done with it).If you don't do this, those handles will eventually be released through finalizers when your AppDomain has unloaded, but you will have no real control regarding "when" that's going to happen.
Edit: Reading your code once again, I overlooked something. The recommended pattern is either
using (var repo = new LibGit2Sharp.Repository(path)) { // Do amazing stuff }
or
var repo = new LibGit2Sharp.Repository(path); // Do amazing stuff repo.Dispose();
Indeed, the
using
statement will automatically issue a call toDispose()
once the code reach the end of the scope.Access to the path 'c16566a7-202a-4c8a-84de-3e3caadd5af9' is denied.
Regarding this point, I think this has nothing to do with LibGit2Sharp.
Is the process (trying to delete the folder named after a guid) running under an identity granted with enough rights to do so?
相关问答
更多-
当你运行代码时会发生什么? 它是否运行完成,但工作目录中没有更改? 如果您尝试使用CheckoutModifiers.Force选项签出,会发生什么情况? CheckoutOptions options = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force }; repo.CheckoutPaths("49916", checkoutPaths, options); What happens when you run tha ...
-
我想删除使用LibGit2Sharp从远程存储库克隆的本地repo文件夹。 我在这里读到,我必须在删除之前Dispose()存储库。 LibGit2Sharp保持.git文件夹中的一些文件(主要是出于性能原因的包文件)。 调用Dispose()将释放这些句柄并释放非托管内存。 因此,依赖using语句确实是一个强烈的建议(或者,至少在完成时使用Dispose()存储库实例)。 如果你不这样做,那么当你的AppDomain卸载时,这些句柄最终将通过终结器发布,但是你将不能真正控制将要发生的“何时”。 编辑:再 ...
-
1)从远程仓库克隆一个分支; // Url of the remote repository to clone string url = "https://github.com/path/to_repo.git"; // Location on the disk where the local repository should be cloned string workingDirectory = "D:\\projects\to_repo"; // Perform the initial clone ...
-
如果你的dev分支存在,那么: git checkout dev 如果您的dev分支尚不存在,那么您将需要创建它,然后切换到它: git checkout -b dev 使用libgit2sharp,无法执行git checkout -b (我知道),因此您需要使用CreateBranch创建分支,然后使用Checkout执行分支检出。 代码如下所示: private void GetOrCreateThenCheckoutBranch(string myPath, string branchName) ...
-
默认情况下LibGit2Sharp.init创建共享存储库? 与git init类似,默认情况下,LibGit2Sharp将使用umask(2)报告的权限。 (即--shared=umask) 截至目前,LibGit2Sharp不支持您要求的内容(例如--shared,--shared --shared=group或--shared=all )。 但是,它看起来已经被底层的libgit2库暴露了。 关于您的问题的最佳操作方法是在LibGit2Sharp 问题跟踪器中记录功能请求。 考虑到这一点,只需要利用底 ...
-
但是,这仍然会留下所有旧提交以及这些提交所特有的任何引用或blob。 我现在的计划是自己清理这些悬挂的GIT物体。 在重写存储库的历史记录时,LibGit2Sharp负责不丢弃重写的引用。 默认情况下,存储它们的命名空间为refs/original 。 这可以通过RewriteHistoryOptions参数进行更改。 为了删除旧的提交,树和blob,首先必须删除这些引用。 这可以通过以下代码实现: foreach (var reference in repo.Refs.FromGlob("refs/ori ...
-
0.22版解决了所有问题。 The Version 0.22 fix all problems.
-
LibGit2Sharp是否支持从本地文件系统克隆存储库?(Does LibGit2Sharp support cloning a repository from the local file system?)[2020-02-19]
所以我的问题是,如果我做错了,或者这是不受支持的功能还是原生git2.dll中的错误? 实际上有点两者兼而有之。 第一个例外显然是一个错误。 这不应该发生,并且会遇到麻烦。 第二个需要更深入的分析。 你是否愿意在LibGit2Sharp项目中打开一个问题? 好消息是BenStraub的拉动请求最近被合并了。 这个拉取请求实现了本地提取传输,这应该可以解决这个问题。 LibGit2Sharp将在接下来的几天内使用新版本的libgit2二进制文件进行更新,这将允许您执行本地克隆/获取。 我会在完成后立即更新此答 ... -
LibGit2Sharp无响应(LibGit2Sharp Unresponsiveness)[2023-09-26]
使用TransferProgress事件在Task运行Clone是我的方法。 基于任务的控制台示例: class MainClass { public static void Main(string[] args) { Task.Run(() => { Repository.Clone("https://github.com/sushihangover/SVGKit.Binding", Path.Combine(Path.GetTemp ... -
使用libgit2sharp导出(Do an export with libgit2sharp)[2022-04-21]
Git不支持部分拉(即只检索一个文件夹)。 但是,git 不允许检索存储库的整个历史记录,而是截断它的版本,只包含n个最新版本。 此操作称为浅克隆 。 目前libgit2 / LibGit2Sharp中没有浅层克隆支持。 然而。 但是,它最终会得到支持。 甚至在LibGit2Sharp问题跟踪器中打开了一个功能请求。 您可以通过订阅问题229来跟踪进度 Git doesn't support a partial pull (ie. retrieving only one folder). However, ...