Home > front end >  PHP Table - Get URL addition from table row
PHP Table - Get URL addition from table row

Time:12-30

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

table result after search

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: table after search 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

CodePudding user response:

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> 

CodePudding user response:

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
                }
                
             }
            ?>
        
    '''
  • Related