重定向到db表存储的链接

时间:2017-05-19 13:35:08

标签: php html mysqli hyperlink

我需要重定向数据库表中存储链接上的点击链接。例如,我点击一个链接,它应该将我重定向到存储的链接,即http://www.hp.com。但它正在重定向到http://localhost/Store_brand/www.hp.com。怎么做?

代码

 <?php
   $q="SELECT c.* , sc.* , sm.* ,ca.* from store_category sc INNER JOIN store_manufacture sm ON sm.sm_id=sc.store_id INNER JOIN categories ca ON ca.cat_id=sc.cat_id INNER JOIN coupons c on c.c_sc_id=sc.sc_id WHERE c.c_date_entered <= CURDATE() AND c.c_date_entered >= DATE(DATE_ADD(CURDATE(), INTERVAL -5 DAY)) LIMIT 3";
   $result=mysqli_query($con,$q);
   while($row=mysqli_fetch_array($result)) {
  ?>
<a class="col-sm-4 tab url" href="<?php echo $row['sm_link'] ?>">
<div class="media">
<div class="media-left media-middle">
<img src="<?php echo $row['cat_image'] ?>" alt=""></div>
<div class="media-body">
  <h4 class="media-heading"><?php echo $row['c_name'] ?></h4>
  <p><?php echo $row['c_description'] ?></p>
    </div> </div>
   </a>
  <?php
   }
   ?>

enter image description here

1 个答案:

答案 0 :(得分:2)

$h = strpos($row['sm_link'],'http');    
<a class="col-sm-4 tab url" href="<?php echo ($h !== FALSE) ? $row['sm_link'] : "http://".$row['sm_link'] ?>">

您需要检查是否在网址中添加了http或https!