0

I'm creating a contact based system, i have a contact list and want it to go to a full contact page when i click on a button, but the variable is being detected as a function?

 <div id="po2" style="Margin:10% ">
 <h1>Contacts</h1>
<?php
$sql = "SELECT * FROM `contacts`";
$query = mysqli_query($conn, $sql);
echo '<table class="data-table">';
  
  echo'<thead>';
   echo'<tr>';
   
    echo '<th>Forename</th>';
    echo '<th>Surname</th>';
    echo '<th>Other</th>';
   echo'</tr>';
  echo '</thead>';
  echo '<tbody>';
  
  
  while ($row = mysqli_fetch_array($query))
{
   echo '<tr>';
    
     echo '<td>'.$row['Forename'].'</td>';
      echo '<td>'.$row['Surname'].'</td>';
        echo $var==$row['Forename']("<td><a href='View.php?ID= " . urlencode($var) ."'>
   <button type='button'>link</button>
  </a></td>");
    
    echo '</tr>';
   }
  

  echo'</tbody>';
  
 echo '</table>';

   
 ?>


</div> 

1 Answers1

1

You are using a comparison of $var and the $row. Try setting $var to the $row each loop iteration.

echo '<thead>';
echo '<tr>';

echo '<th>Forename</th>';
echo '<th>Surname</th>';
echo '<th>Other</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';


while ($row = mysqli_fetch_array($query))
{ 
    $var = $row['Forename'];
    echo '<tr>';

    echo '<td>' . $var . '</td>';
    echo '<td>' . $row['Surname'] . '</td>';        
    echo "<td><a href='View.php?ID=" . urlencode($var) . "'><button type='button'>link</button></a></td>";

    echo '</tr>';
}

echo '</tbody>';
Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
Ryan Peterson
  • 132
  • 1
  • 9