1

I have the following: A php foreach loop that fetches info and displays it in a table. What I want to do is then make my Client Code row clickable so that it will open a modal contain the info of that client linked to that client code.

Issue 1: How do I actually make the client code in my table clickable. My loop looks like this

foreach ($results as $rows)
       {
       echo
       "<tr>
         <td>" . $rows['Client_Code'] . "</td>
         <td>" . $rows['firstname'] . "</td>
         <td>" . $rows['lastname'] . "</td>
         <td>" . $rows['Service_Name'] . "</td>
         <td>" . $rows['Physical_Address'] . "</td>
         <td>" . $rows['Cell'] . "</td>
         <td>" . $rows['billingemail'] . "</td>
         <td>" . $rows['Business_Name'] . "</td>
         <td>
       </tr>";
     }

If I understand correctly I should do this

foreach ($results as $rows)
       {
       echo
       "<tr>
         <td><button type="button" class="btn btn-outline-success block btn-lg" data-toggle="modal" data-target="#xlarge">" . $rows['Client_Code'] . "</td></button>
         <td>" . $rows['firstname'] . "</td>
         <td>" . $rows['lastname'] . "</td>
         <td>" . $rows['Service_Name'] . "</td>
         <td>" . $rows['Physical_Address'] . "</td>
         <td>" . $rows['Cell'] . "</td>
         <td>" . $rows['billingemail'] . "</td>
         <td>" . $rows['Business_Name'] . "</td>
         <td>
       </tr>";
     }
       ?>

This however gives me an error: Parse error: syntax error, unexpected 'button' (T_STRING), expecting ',' or ';'

and also my editor does not like it

Code is hashed out?

Issue 2: How do select the php data for that user to be used in my modal?

Your help would be appretiated

Thanks

Sean Konig
  • 124
  • 1
  • 12

2 Answers2

1
<?php

foreach ($results as $rows) {
    echo
        "<tr>
         <td><button type='button' class='btn btn-outline-success block btn-lg' data-toggle='modal' data-target='#xlarge'>'" . $rows['Client_Code'] . " '</td></button>
<td>' " . $rows['firstname'] . "'</td>
         <td>'" . $rows['lastname'] . "'</td>
         <td>'" . $rows['Service_Name'] . "'</td>
         <td>'" . $rows['Physical_Address'] . "'</td>
         <td>'" . $rows['Cell'] . "'</td>
         <td>'" . $rows['billingemail'] . "'</td>
         <td>'" . $rows['Business_Name'] . "'</td>
         <td>
       </tr>";
}
?>

you mixed up with " and ' quotes

Exprator
  • 26,992
  • 6
  • 47
  • 59
  • Cool, this fixed the first issue. Thank you very much for pointing out the " and ' quotes issue – Sean Konig Jul 12 '17 at 06:32
  • you are welcome, and you need to follow a rule, if you have more than 1 issue then you need to create n number of questions for n number of issue, hope you understand, anyways cheers mate :) – Exprator Jul 12 '17 at 06:34
  • Thanks I will first give it a go myself now that my modal is working. I will post another question if needed. Thank you for pointing that out as well. Cheers mate – Sean Konig Jul 12 '17 at 06:41
0

use single quote inside double quotes like this:-

<td><button type='button' class='btn btn-outline-success block btn-lg' data-toggle='modal' data-target='#xlarge'>" . $rows['Client_Code'] . "</button></td>

replace your first <td> with this code

Harpreet Singh
  • 999
  • 9
  • 19