在php中链接返回值

时间:2018-06-14 16:08:36

标签: php mysql html5

我有一个脚本正在查找存储在数据库中的跟踪号码。目前,它将跟踪号作为文本返回。如何使它成为一个超链接,将返回的结果放入链接

我需要添加http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums= {tracking_number}链接

    <html>
<head>
<title>Search</title>
</head>

<body>
<div class="logo" align="center">
    <img src="./gplogo.png">
    </div>
    <form action="./index.php" method="get" align="center" ><br>
    <h1>Sample Order Tracking</h1>

    <label>Search By Company, Zip, or City:
        <input type="text" name="keywords">
    </label>
        <input type="submit" value="search" autocomplete="off">
    </form>


    <?php

   $db = new mysqli("localhost", "root", "", "samples");

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

        $keywords = $db->escape_string($_GET['keywords']);

        $query = $db->query("
            SELECT Company, Attention, Address1, ST_City, ST_State, ST_PostalCode, Pak_TrackingNumber
            FROM samples
            WHERE ST_PostalCode LIKE '%{$keywords}%'
            OR Company LIKE '%{$keywords}%'
            OR ST_City LIKE '%{$keywords}%'
        ");
   ?>



   <div class="resul-count" align="center">
    Found <?php echo $query->num_rows; ?> Results.
    </div><br>
<table border="1" align="center" cellpadding="15px">    
    <?php

        if($query->num_rows){
            while($r = $query->fetch_object()){
            ?>
            <div class="result">
                    <tr>
    <td><?php echo $r->Company;   ?></td>
    <td><?php echo $r->Attention; ?></td>
    <td><?php echo $r->Address1; ?></td>
    <td><?php echo $r->ST_City;   ?></td>
    <td><?php echo $r->ST_State; ?></td>
    <td><?php echo $r->ST_PostalCode; ?></td>
    <td><?php echo $r->Pak_TrackingNumber; ?></td>
</tr>
                </div>
            <?php
        }

}
}   
?>
</body>

</html>

2 个答案:

答案 0 :(得分:0)

你只需要用一个像这样的href标签包装它:

<td><a href="http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=<?= $r->Pak_TrackingNumber; ?>"><?= $r->Pak_TrackingNumber;?></a></td>

答案 1 :(得分:0)

尝试将其嵌入&lt; a&gt; balise标签:

echo "<a href='http://www.apps.ups.com/WebTracking/track?track=yes&trackNums=$yourVariable'>redirect_link</a>";