简体   繁体   中英

Link SQL query result in PHP

I have a sql query witch search students name from sql database it shows results now i want to link each result get http url www.tlss.edu.pk/result.php?r=1 if Sr_=1 my SQL Query is

<?php
include 'form.html';
$r1=$_GET["r"];
$n1=$_GET["n"];
// Create connection
$con=mysqli_connect("localhost","chumspai_tlss","Tls121","chumspai_tlsResult");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  echo $n1;
$result = mysqli_query($con,"SELECT * FROM nursery_blue_ WHERE students_names like '%$n1%'");

while($row = mysqli_fetch_array($result))
{

echo '<pre>';
    print_r ($row['sr_']. '.'. $row['students_names']);
    echo '</pre>';
  }
    ?>

May be you need to try like

while($row = mysqli_fetch_array($result))
{
     //print_r ($row['sr_']. '.'. $row['students_names']);
     if($row['sr_'] == 1) {
        echo "<a href='www.tlss.edu.pk/result.php?r=".$row['sr_']."'>"
              .$row['students_names']."</a>";
     }
 }

If you want all the results then you can remove the if condition here.

add an link in your loop and if you have any condition add condition for show link

while($row = mysqli_fetch_array($result)) {
   echo "<a href='http://www.tlss.edu.pk/result.php?r=".$row['sr_']."'>".$row['students_names']."</a>";
 }

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