简体   繁体   中英

PHP Table - Get URL addition from table row

I have the following table which pulls information from a MySql database and shows in the table perfectly.

搜索后的表格结果

However, I am trying to get the image in rows 'Edit Record' and 'Link to Record' to be URL
'''a href="editcandidatecard.php?pr=6050'''

The following:

''' <?php

             if(!$employee_details)
             {
                echo '<tr>No data found</tr>';
             }
             else{
                foreach($employee_details as $key=>$value)
                {
                    ?>
                <tr>
                <td><?php echo $key+1;?></td>
                <td><?php echo '<a href="editcandidatecard.php?no=" ' . $row['payroll_number'] . '</a>'?><img src="images/document.gif" height="30" ></td>                  
                <td><?php echo '<a href="editcandidatecard.php?no="> ' . $value['payroll_number'] . '</a>'?><img src="images/document.gif" height="30" ></td>   
                <td><?php echo $value['payroll_number'];?></td>
                <td><?php echo $value['title'], '&nbsp;', $value ['first_name'], '&nbsp;', $value ['last_name'];?></td>
                <td><?php echo $value['mobile_number'];?></td>
                <td><?php echo $value['home_number'];?></td>
                <td><?php echo $value['email_address'];?></td>
                </tr>
                    
                    <?php
                }
                
             }
            ?>
        
    

''' Gives: 搜索 URL 后的表格

  1. The Url shown by: ''''?>''' Is - editcandidatecard.php?no=
  2. The Url shown by: ''' '. $value['payroll_number']. ''?>''' IS - editcandidatecard.php?no=

I want to achieve a url of editcandidatecard.php?no=6050

Where the 6050 is pulled from the value shown in the 'payroll number'

Many thanks in advance for your help

You have to place images between a tags like below.

<td><?php echo '<a href="editcandidatecard.php?no=" ' . $value['payroll_number'] . ' ">'; ?><img src="images/document.gif" height="30" /></a></td>
<td><?php echo '<a href="editcandidatecard.php?no=" ' . $value['payroll_number'] . ' ">'; ?><img src="images/document.gif" height="30" /></a></td>

As a more readable and simple approach, the following snippet can be used.

<td><a href="editcandidatecard.php?no=<?= $value['payroll_number'] ?>"><img src="images/document.gif" height="30" /></a></td>
<td><a href="editcandidatecard.php?no=<?= $value['payroll_number'] ?>"><img src="images/document.gif" height="30" /></a></td> 

Thank you @Ozan Budak

Complete working code:

''' <?php

             if(!$employee_details)
             {
                echo '<tr>No data found</tr>';
             }
             else{
                foreach($employee_details as $key=>$value)
                {
                    ?>
                <tr>
                
                <td><?php echo $key+1;?></td>
                <td><a href="editcandidatecard.php?pr=<?= $value['payroll_number'] ?>"><img src="images/document.gif" height="30" ></a></td>                    
                <td><a href="candidatecard.php?pr=<?= $value['payroll_number'] ?>"><img src="images/document.gif" height="30" ></a></td>    
                <td><?php echo $value['payroll_number'];?></td>
                <td><?php echo $value['title'], '&nbsp;', $value ['first_name'], '&nbsp;', $value ['last_name'];?></td>
                <td><?php echo $value['mobile_number'];?></td>
                <td><?php echo $value['home_number'];?></td>
                <td><?php echo $value['email_address'];?></td>
                </tr>
                    
                    <?php
                }
                
             }
            ?>
        
    '''

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