duanqiu3800 2014-01-20 06:53
浏览 11
已采纳

在php-sql中,我想在第一个搜索结果表中重新搜索。

In php-sql, I want to re-search within the first search result table. This is the captured picture executed by my php-mysql code.

enter image description here

I want to use the button "Search below result" to gain the detailed result from the first search result table. Then, "Search in below result" form action is another php code which has to hold the first result, and have the sql code that is as like

     select uid, contents from datatable where contents like '%re-search word%'
     and uid in (select uid from datatable where contents like '%first-search word%')

but I have a question and don't know how uid works. How can i produce uid? What is uid? Where is uid information? How can i use uid as like above the sql code?

Below is my first-search php code

  <?php
  $q = $_GET['q'];
  $con = mysqli_connect('localhost','root','autoset','my_db');
  if (!$con)
  {
  die('Could not connect: ' . mysqli_error($con));
   }

  mysqli_select_db($con,"ajax_demo");
  $sql="SELECT * FROM persons WHERE FirstName = '".$q."' ;

  $result = mysqli_query($con,$sql);

  echo "<table border='1'>
  <tr>
  <th>Firstname</th>
  <th>Lastname</th>
  <th>Age</th>
  <th>Hometown</th>
  <th>Job</th>
   </tr>";

  while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";
  echo "</tr>";
   }
 echo "</table>";
 mysqli_close($con);
 ?> 

and How can i re-use the first-search word variable in the another php code? Another php code is designed as like below

   <?php
  $q = $_GET['q'];
  $p = $_GET['LastName'];
  $con = mysqli_connect('localhost','root','autoset','my_db');
  if (!$con)
  {
  die('Could not connect: ' . mysqli_error($con));
   }

  mysqli_select_db($con,"ajax_demo");
  $sql="SELECT uid, * FROM persons WHERE LastName = '".$p."' and select **uid** in (select uid from datatable where FirstName='".$q."') ;

  $result = mysqli_query($con,$sql);

  echo "<table border='1'>
  <tr>
  <th>Firstname</th>
  <th>Lastname</th>
  <th>Age</th>
  <th>Hometown</th>
  <th>Job</th>
   </tr>";

  while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";
  echo "</tr>";
   }
 echo "</table>";
 mysqli_close($con);
 ?> 

Above code, I think uid is important to recall the first search result. But How can i get uid and set uid in php code or html code??

Please help me!

  • 写回答

1条回答 默认 最新

  • doufu6196 2014-01-20 07:40
    关注

    Q1: How can i produce uid? A1: It should be a column in your table you created in mysql. Your create table statement would have looked something like:

    CREATE TABLE persons (
         uid INT(10) NOT NULL AUTO_INCREMENT,
         FirstName CHAR(30) NOT NULL,
         LastName CHAR(30) NOT NULL,
         Age INT(3),
         Hometown CHAR(40),
         Job CHAR(40),
         PRIMARY KEY (uid)
    );
    


    Q2: How can i produce uid?
    A2: You won't have to. The AUTO_INCREMENT field will create itself for you when you insert an entry. doco for auto-increment here

    Q3: What is uid?
    A3: It likely stands for "user identification" which is a number unique to a user. No other user may have that number in their "uid" field.

    Q4: Where is uid information?
    A4: It's in your table

    Q5: How can i use uid as like above the sql code?
    A5: Providing that you created it in your "create table" statement like I mentioned in A1 then you should be able to access uid with the query you presented above but should look more like:

    SELECT uid FROM persons WHERE LastName = '".$p."' AND FirstName ='".$q."';
    

    OR if you want to run a test query with a name you know is in your database then something like below:

    SELECT uid FROM persons WHERE LastName = 'timmy' AND FirstName ='tom';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥15 C#不用正则表达式如何全字匹配
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信
  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题