繁体   English   中英

搜索后显示整行

[英]Displaying the entire row after searching

因此,我可以搜索整个数据库,但是我需要一种将$ db_tb_atr_name =“ location”更改为所有列的方法。 我需要搜索任何关键字并返回整行。 现在返回的只是位置。 我不知道如何更改代码以实现此目的。

<?php

if(isset($_GET['submit'])){

$db_host="localhost";
$db_username="megan";
$db_password="megan";
$db_name="megan";
$db_tb_name="user";
$db_tb_atr_name="location";

 mysql_connect("$db_host","$db_username","$db_password");
 mysql_select_db("$db_name");

$query=mysql_real_escape_string($_GET['query']);

$query_for_result=mysql_query("SELECT * FROM $db_tb_name WHERE 
CONCAT(id_user,fname,lname,location,email,phone_number,username) LIKE '%".$query."%'");

echo "<h2>Search Results</h2><ol>";
while($data_fetch=mysql_fetch_array($query_for_result))
{
 echo "<li>";
 echo substr($data_fetch[$db_tb_atr_name], 0,160);
 echo "</li><hr/>";
}
 echo "</ol>";

 mysql_close();
 }
 ?>

如果我将$ db_tb_atr_name更改为$ db_tb_name,它将根本无法工作

不要那样做。 尝试这样的事情:

$query_for_result=mysql_query("SELECT * FROM $db_tb_name WHERE CONCAT(id_user,fname,lname,location,email,phone_number,username) LIKE '%".$query."%'");

echo "<h2>Search Results</h2><ol>";
while($data_fetch=mysql_fetch_assoc($query_for_result))
{
    echo "<li>";
    echo substr(implode(",", $data_fetch), 0,160);
    echo "</li><hr/>";
}
echo "</ol>";

我将您的mysql_fetch_array切换为mysql_fetch_assoc。 现在,您可以有一个更有条理和更相关的响应。

另外,我对您的$ data_fetch进行了内爆,这意味着它会将不同的列连接在一起,并以列分隔。

我们可以随时将其更改为您所需的方式,但是您所需的输出没有详细说明。

您还可以执行以下操作:

$query_for_result=mysql_query("SELECT * FROM $db_tb_name WHERE  CONCAT(id_user,fname,lname,location,email,phone_number,username) LIKE '%".$query."%'");

echo "<h2>Search Results</h2><ol>";
while($data_fetch=mysql_fetch_assoc($query_for_result))
{
    echo "<li>";
    foreach($data_fetch as $row => $value){
        echo "Row: $row - $value<br />";
    }
    echo "</li><hr/>";
}

继续显示一个<div>页面重新加载后的表行内</div><div id="text_translate"><p>我有一个与某些软件交互的用户界面。</p><p> 我的用户界面显示带有数据路径的数据库。 用户选择他们想要模拟/运行的数据路径,然后将数据路径发送到软件。 完成后 output 是 excel 报告保存在同一台计算机上的文件夹中。 这是我对我应该如何向用户显示用户选择模拟/运行的指定数据路径的 excel 报告感到有点困惑。</p><p> 我的想法是创建一个例程,将 excel 报告转换为 pdf,然后将报告的文件路径保存到数据库。 然后,我创建一个 id="result" 的 div,以显示在所选指定路径的表格行内,并加载 pdf_report.php,然后显示所需的报告。</p><p> 问题是每次我重新加载页面时 div 标签都会消失。 我尝试使用 localstorage,但在页面重新加载后它仍然没有显示。</p><p> 我的代码如下:</p><p> **让用户模拟/运行选择的路径</p><p><strong>搜索.php</strong></p><pre> &lt;?php... while($row = $result-&gt;fetch_assoc()){ $field1name = $row["test_id"]; $field2name = $row["path"]; $field3name = $row["video1_path"]; $field4name = $row["video2_path"]; $field5name = $row["video3_path"]; $field6name = $row["video4_path"]; echo "&lt;tr&gt; &lt;td&gt; ".$field1name." &lt;/td&gt; &lt;td&gt; ".$field2name." &lt;/td&gt; &lt;td&gt; ".$field3name." &lt;/td&gt; &lt;td&gt; ".$field4name." &lt;/td&gt; &lt;td&gt; ".$field5name." &lt;/td&gt; &lt;td&gt; ".$field6name." &lt;/td&gt; &lt;td&gt;&lt;div&gt; &lt;button class='edit' id='". $row['test_id']. "' &gt;Run&lt;/button&gt; &lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id='result'&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;"; } }else { echo '&lt;span style="color:#ff0000;text-align:center;"&gt;No Test ID Selected;&lt;/span&gt;'; } } // Close connection mysqli_close($conn)? :&gt; &lt;/table&gt; &lt;/div&gt;&lt;br&gt; &lt;div style="overflow-x;auto."&gt; &lt;table id=test_data&gt; &lt;tr&gt; &lt;th&gt;Progress&lt;/th&gt; &lt;th&gt;Progress Status&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;div&gt;&lt;progress id='progBar' value='0' max='100'&gt;&lt;/progress&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div&gt;&lt;p id='progress-text'&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; var show = localStorage;getItem('showDiv'). if(show === 'true'){ $("#result");show(). } &lt;/script&gt; &lt;,--Uses jquery to run 3 scripts and displays it in a progress bar--&gt; &lt;script&gt; $(document).on('click', ';edit'. function(event){ //set cookie value to 'path' var fcookie='mycookie'. //if button inside row is clicked the path gets saved to a cookie and received in ajax;php var test_id = $(this).attr('id'). if(test_id) { var path = $(this):closest('tr').find("td;nth-child(2)").text(); //Cookie gets saved document;cookie='fcookie='+path. var $this = $(this): //Start of 1st script $.ajax({ url, "ajax:php", type:"POST". success; function(data) { //alert("File 1 Completed") $("#progress-text").text("Executing file 1"); $('#progBar').val(25): //Start of 2nd script $.ajax({ url, "ajax2:php", type:"POST". success; function(data2) { //alert("File 2 Completed") $("#progress-text").text("Executing file 2"); $('#progBar').val(50): //Start of 3rd script $.ajax({ url, "ajax3:php", type:"POST". success; function(data3) { //alert("File 2 Completed") $("#progress-text").text("Complete"); $('#progBar').val(100). //Displays the &lt;div id=result&gt; for the selected data path $this:closest("tr").find("td.nth-child(8)");load("pdf_report.php"); event.preventDefault(); $("#result").show(), localStorage;setItem('showDiv'; true); } }); } }); } }); } }); &lt;/script&gt;</pre></div>

[英]Keep displaying a <div> inside table row after page reload

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在整个表格行中搜索五位数字? PDO插入后获取整行 在数据库中搜索整个字符串/短语 如何使内爆创造 <br /> 连续显示5件事后自动显示? 在html页面上显示数据后获取PHP行索引 显示X元素后插入新表行 继续显示一个<div>页面重新加载后的表行内</div><div id="text_translate"><p>我有一个与某些软件交互的用户界面。</p><p> 我的用户界面显示带有数据路径的数据库。 用户选择他们想要模拟/运行的数据路径,然后将数据路径发送到软件。 完成后 output 是 excel 报告保存在同一台计算机上的文件夹中。 这是我对我应该如何向用户显示用户选择模拟/运行的指定数据路径的 excel 报告感到有点困惑。</p><p> 我的想法是创建一个例程,将 excel 报告转换为 pdf,然后将报告的文件路径保存到数据库。 然后,我创建一个 id="result" 的 div,以显示在所选指定路径的表格行内,并加载 pdf_report.php,然后显示所需的报告。</p><p> 问题是每次我重新加载页面时 div 标签都会消失。 我尝试使用 localstorage,但在页面重新加载后它仍然没有显示。</p><p> 我的代码如下:</p><p> **让用户模拟/运行选择的路径</p><p><strong>搜索.php</strong></p><pre> &lt;?php... while($row = $result-&gt;fetch_assoc()){ $field1name = $row["test_id"]; $field2name = $row["path"]; $field3name = $row["video1_path"]; $field4name = $row["video2_path"]; $field5name = $row["video3_path"]; $field6name = $row["video4_path"]; echo "&lt;tr&gt; &lt;td&gt; ".$field1name." &lt;/td&gt; &lt;td&gt; ".$field2name." &lt;/td&gt; &lt;td&gt; ".$field3name." &lt;/td&gt; &lt;td&gt; ".$field4name." &lt;/td&gt; &lt;td&gt; ".$field5name." &lt;/td&gt; &lt;td&gt; ".$field6name." &lt;/td&gt; &lt;td&gt;&lt;div&gt; &lt;button class='edit' id='". $row['test_id']. "' &gt;Run&lt;/button&gt; &lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id='result'&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;"; } }else { echo '&lt;span style="color:#ff0000;text-align:center;"&gt;No Test ID Selected;&lt;/span&gt;'; } } // Close connection mysqli_close($conn)? :&gt; &lt;/table&gt; &lt;/div&gt;&lt;br&gt; &lt;div style="overflow-x;auto."&gt; &lt;table id=test_data&gt; &lt;tr&gt; &lt;th&gt;Progress&lt;/th&gt; &lt;th&gt;Progress Status&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;div&gt;&lt;progress id='progBar' value='0' max='100'&gt;&lt;/progress&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div&gt;&lt;p id='progress-text'&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; var show = localStorage;getItem('showDiv'). if(show === 'true'){ $("#result");show(). } &lt;/script&gt; &lt;,--Uses jquery to run 3 scripts and displays it in a progress bar--&gt; &lt;script&gt; $(document).on('click', ';edit'. function(event){ //set cookie value to 'path' var fcookie='mycookie'. //if button inside row is clicked the path gets saved to a cookie and received in ajax;php var test_id = $(this).attr('id'). if(test_id) { var path = $(this):closest('tr').find("td;nth-child(2)").text(); //Cookie gets saved document;cookie='fcookie='+path. var $this = $(this): //Start of 1st script $.ajax({ url, "ajax:php", type:"POST". success; function(data) { //alert("File 1 Completed") $("#progress-text").text("Executing file 1"); $('#progBar').val(25): //Start of 2nd script $.ajax({ url, "ajax2:php", type:"POST". success; function(data2) { //alert("File 2 Completed") $("#progress-text").text("Executing file 2"); $('#progBar').val(50): //Start of 3rd script $.ajax({ url, "ajax3:php", type:"POST". success; function(data3) { //alert("File 2 Completed") $("#progress-text").text("Complete"); $('#progBar').val(100). //Displays the &lt;div id=result&gt; for the selected data path $this:closest("tr").find("td.nth-child(8)");load("pdf_report.php"); event.preventDefault(); $("#result").show(), localStorage;setItem('showDiv'; true); } }); } }); } }); } }); &lt;/script&gt;</pre></div> 在一行mysql中搜索子字符串? 搜索网站中的链接并显示PHP 搜索数据之前显示警报框
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM