简体   繁体   中英

How to select a result from a result that return by a SQL

I'm using SQL and PHP to pull information from my database and it returned a list of users that met the criteria. And I need to redirect to another page using the selected amount from the picture below. How can I grab this amount to another page? For example, when I click the first select, I can go to the other page that showing $24, and Rubinsztein Abdel, 182 Crownhardt Lane...

在此处输入图像描述

    <!--loader end-->
  <!-- Main  -->
  <div id="main">
    <!-- wrapper -->
    <div id="wrapper">
      <div class="content">
        <!-- Map -->
        <div class="map-container column-map right-pos-map">
          <div id="map-main"></div>
          <ul class="mapnavigation"></ul>
          <div class="scrollContorl mapnavbtn" title="Enable Scrolling"><span><i class="fa fa-lock"></i></span></div>
        </div>
        <!-- Map end -->
        <!--col-list-wrap -->
        <div class="col-list-wrap left-list">
          <!-- list-main-wrap-->
          <div class="list-main-wrap fl-wrap card-listing">
              <!-- listing-item -->
              <?php
              ini_set('display_errors', 1);
              ini_set('display_startup_errors', 1);
              error_reporting(E_ALL);

              $severname = "localhost";
              $username = "root";
              $password = "";
              $dbname = "dbn";

                //$conn = mysqli_connect('xx', 'xx', 'xx','xx');
              $conn = mysqli_connect('dxx', 'xx', 'xx','xx');
              //check connection
              if (mysqli_connect_errno())
              {echo nl2br("Failed to connect to MySQL: ". mysqli_connect_error() . "\n"); }
              else
              { echo nl2br("");}

              $city = mysqli_real_escape_string($conn, $_POST['city']);
              $date1 = mysqli_real_escape_string($conn, $_POST['date1']);
              $date2 = mysqli_real_escape_string($conn,$_POST['date2']);
              $pet = mysqli_real_escape_string($conn, $_POST['pet']);

              //var_dump($date2);

              $sql = "SELECT CONCAT(s.lname, ' ', s.fname) AS fullName, s.ratings, s.rate, s.phone, s.address FROM Pet_Sitter AS s WHERE s.citystate='".$city."' AND s.pet_type='".$pet."' "
                  ;
              //echo $sql."<br/>";
              $result = mysqli_query($conn,$sql);
              if (!$result) {
                  printf("Error: %s\n", mysqli_error($conn));
                  exit();
              }

              if ($result=mysqli_query($conn,$sql))
                {
                // Return the number of rows in result set
                $rowcount=mysqli_num_rows($result);
                printf("");
                }

              //var_dump($result);

              $num_rows = mysqli_num_rows($result);
              ?> <div class="container"> <?php


              if ($result->num_rows > 0) {
                while ($row = $result->fetch_assoc()) {
                //var_dump($row);
                // echo "<tr><td>" . $row['fullName'] . " </td><td>" . $row['ratings'] . " </td><td>" . $row['rate'] . " </td></tr>";
                // echo '<div class="listing-item">';
                echo '<div class="listing-item">';
                echo '<article class="geodir-category-listing fl-wrap">';
                echo '<div class="geodir-category-img">';
                echo '<img src="../images/all/1.jpg" alt="">';
                echo '<div class="overlay"></div>';
                echo '<div class="list-post-counter"><span>' . $row['rate'] . '</span></div>';
                echo '</div>';
                echo '<div class="geodir-category-content fl-wrap">';
                echo '<a class="listing-geodir-category" href="../index.html">Pet sitting</a>';
                echo '<h3><a href="../index.html">' . $row['fullName'] . '</a></h3>';
                echo '<p>PET-SITTER INFORMATION</p>';
                echo '<div class="geodir-category-options fl-wrap">';
                echo '<span>' . 'Reviews ' . $row['ratings'] .'</span>';
                echo '<div class="geodir-category-location">'. $row['address'] . " · " . $row['phone'] .
                '</div>';
                echo '</div>';
                echo '</div>';
                echo '</article>';
                echo '</div>';
              }?>
              <?php



              } else {
                  echo "0 results";
                }
                  mysqli_close($conn);

              ?>

            </div>
          </div>

An easy way to do it is to create one page (the one you wanna go if you click on your items) and use GET on URL to get the page id;

On your actual page you will use a link like:

<a href="new-page.php?id=<?php echo $row['id']; ?>"

Here the ?id= on URL is a parameter, that you can get on the other page:

$pageId = $_GET['id'];

Then, you just have to make a SQL request

SELECT * FROM Pet_Sitter WHERE id=$pageId

(better to use prepare and execute for this request as the value of $pageId can be change by everybody by changing the URL).

So every time you click on a link, the page will display the matching informations.

Also you should closed <?php when you are writing HTML instead of using a lot of echo .

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