2017-09-01 60 views
0
+------------------+ 
| Tables_employees | 
+------------------+ 
| empid   | 
| aid    | 
| FirstName  | 
| LastName   | 
| Email   | 
| Phone   | 

<table id="exampleC" class="display" cellpadding="1" cellspacing="1" width="" style="font-size:small;"> 
    <thead> 
     <tr> 
      <th>1st Name</th> 
      <th>2nd Name</th> 
      <th>Title</th> 
      <th>Email</th> 
      <th>Phone(D)</th> 
      <th>Linkedin</th> 
     </tr> 
    </thead> 
    <tbody> 
     <?php 
     require_once 'tabconnect.php'; 
     if (isset($_GET['id'])) { 
      $id = $_GET['id']; 
      $data = mysqli_query($connection,"SELECT acquisition.aid,acquisition.aby,employees.empid,employees.aid,employees.FirstName,employees.LastName,employees.title,employees.email,employees.phone,employees.dphone,employees.LIUrl,employees.listatus FROM employees JOIN acquisition ON acquisition.aid=employees.aid where acquisition.aid=$id"); 

       while ($row3 = mysqli_fetch_array($data)) { ?> 
      <tr> 
       <td><?php echo $row3['FirstName']; </td> 
       <td><?php echo $row3['LastName']; ?</td> 
       <td><?php echo $row3['title']; ?></td> 
       <td><a class="" href="<?php echo $row3['email']; ?>" target="_blank"><i class="icon-custom icon-sm rounded-x fa fa fa-envelope"></i></td>          
       <td><a class="" href="<?php echo $row3['phone']; ?>" target="_blank"><i class="icon-custom icon-sm rounded-x fa fa-phone"></i></td>          
      </tr>      
     <?php 
       } 
     } 
     ?> 
    </tbody> 
</table> 

問題是,它會顯示所有的電子郵件和電話中的圖像,但我想顯示圖像時,纔會有會在表中的記錄不顯示從MySQL表中的PHP空的結果

+0

您需要在SQL注入閱讀起來。 – jeroen

+0

很高興看到一些示例表格數據以及您實際想要在PHP中顯示的內容。 –

+0

你的問題不清楚你想要什麼。只有在存在圖像數據時才顯示圖像的最後一行,或者只有存在圖像時才顯示其他數據? – Sand

回答

0

它不清楚要填寫所有有圖標的記錄或唯一記錄,可以檢查領域,如下面:

<?php 
    while ($row3 = mysqli_fetch_array($data)) { 
    ?> 
    <tr> 
     <td><a class="" href="<?php echo ($row3['email'])?$row3['email']:''; ?>" target="_blank"> 
      <?php if($row3['email']!=''){ echo '<i class="icon-custom icon-sm rounded-x fa fa fa-envelope"></i>'; 
      }else{echo '';} ?></td>          
     <td><a class="" href="<?php echo ($row3['phone'])?$row3['phone']:''; ?>" target="_blank"> 
      <?php if($row3['email']!=''){ echo '<i class="icon-custom icon-sm rounded-x fa fa-phone"></i>'; } 
      else{echo '';}</td>          
    </tr>      
<?php 
     } 
?> 
+0

當表中有記錄時顯示圖標否則圖標不會顯示 –

+0

現在查看我的回答 –

+0

它的工作原理。非常感謝。只是另一個查詢,當我點擊LI圖標,會出現一條消息「找不到對象! 在此服務器上找不到請求的URL。推薦頁面上的鏈接似乎是錯誤或過時的。如果您認爲這是服務器錯誤,請聯繫網站管理員。 錯誤404 localhost Apache/2.4.18(Win32)OpenSSL/1.0.2e PHP/7.0.8「我如何將克服它 –

0
<?php if ($row3['email'] && $row3['phone']) { ?> 

<td><a class="" href="<?php echo $row3['email']; ?>" target="_blank"><i class="icon-custom icon-sm rounded-x fa fa fa-envelope"></i></td>          
<td><a class="" href="<?php echo $row3['phone']; ?>" target="_blank"><i class="icon-custom icon-sm rounded-x fa fa-phone"></i></td> 


<?php } ?> 

檢查電話和電子郵件是否爲空,然後顯示電話和電子郵件圖標。