首页 \ 问答 \ 使用PHP进行精确值搜索(Exact value search with PHP)

使用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 only 1 but also the data containing 1 like 11, 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
更新时间:2022-09-24 21:09

最满意答案

我想删除使用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 to Dispose() 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 to Dispose() 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.
  • 所以我的问题是,如果我做错了,或者这是不受支持的功能还是原生git2.dll中的错误? 实际上有点两者兼而有之。 第一个例外显然是一个错误。 这不应该发生,并且会遇到麻烦。 第二个需要更深入的分析。 你是否愿意在LibGit2Sharp项目中打开一个问题? 好消息是BenStraub的拉动请求最近被合并了。 这个拉取请求实现了本地提取传输,这应该可以解决这个问题。 LibGit2Sharp将在接下来的几天内使用新版本的libgit2二进制文件进行更新,这将允许您执行本地克隆/获取。 我会在完成后立即更新此答 ...
  • 使用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 ...
  • Git不支持部分拉(即只检索一个文件夹)。 但是,git 不允许检索存储库的整个历史记录,而是截断它的版本,只包含n个最新版本。 此操作称为浅克隆 。 目前libgit2 / LibGit2Sharp中没有浅层克隆支持。 然而。 但是,它最终会得到支持。 甚至在LibGit2Sharp问题跟踪器中打开了一个功能请求。 您可以通过订阅问题229来跟踪进度 Git doesn't support a partial pull (ie. retrieving only one folder). However, ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。