简体   繁体   中英

In php-sql, I want to re-search within the first search result table.

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.

在此处输入图片说明

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!

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM