0

I am trying to make a table which displays logs for users that have logged in to the system. The logs are working perfectly,but i want the tables on the final table column to lead me to the member's information. Assigning the member id column value for individual rows so i can use them as 'WHERE' in the queries is the problem

Note The member_id column is a foreign key that links to the member information table the member details on the other hand are in another table where the member_id is a primary key The buttons should take me to the member's information using the member_id of the table row that the button is in

echo "<table border = 2>"; // start a table tag in the HTML

echo "<tr>
         <td>Member ID</td>
         <td>Date</td>
         <td>Time</td>
         <td>Member Info</td>
   </tr>";
while($row = mysql_fetch_array($result)){   //Creates a loop to loop through results
  echo "<tr>
          <td>" . $row['member_id'] . "</td>
          <td>" . $row['date'] . "</td>
          <td>" . $row['time'] . "</td>
          <td><input type= 'submit' value = 'Member Information' onsubmit ='memberinfo.php'></td>
           //this button is the one to open member information
</tr>";
}

echo "</table>"; //Close the table in HTML

mysql_close(); 
 ?>
2
  • 1
    sidenote: stop using deprecated mysql_* functions. use MySQLi or PDO instead. Here is a good tutorial for PDO. Commented Mar 28, 2014 at 7:40
  • Border attribute is deprecated in <table>. Use CSS instead. Also, use quotes to enclose all attribute values. Commented Mar 28, 2014 at 7:41

3 Answers 3

1

You only need to pass the member ID to memberinfo.php using:

echo "<tr>
<td>" . $row['member_id'] . "</td><td>" . $row['date'] . "</td>
<td>" . $row['time'] . "</td>
<td><a href='memberinfo.php?id=" . $row['member_id'] . "'>Member Information</a></td>
</tr>";

Do not use multiple submit button in same page (submit button should work within form tags only). Hyperlink is more suitable in your case.

Note: Of course your memberinfo.php needs to fetch the member ID from $_GET['id'].

Sign up to request clarification or add additional context in comments.

Comments

0

Instead of:

<td><input type= 'submit' value = 'Member Information' onsubmit = 'memberinfo.php'></td>

Would this do?

<td><a href='memberinfo.php?id=<?php echo $row['member_id'];?>'>Member Information</a></td>

You'd them need to handle $_GET['id'] on memberinfo.php to pull the correct record and do whatever. You'd maybe need to style the link appropriately.

Comments

0

Change this line

 <td><input type= 'submit' value = 'Member Information' 
     onsubmit ='memberinfo.php'></td>

to

 <td><input type= 'button' value = 'Member Information' 
     onclick ='memberinfo.php?id=".$row['id']."'></td>

You could get the value by using $_GET['id'] in memberinfo.php. As far as passing the date and time is concerned you could store it in the session and later unset it after transferring the values to variables in memberinfo.php.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.