0

I need a little help determining method of coding that would allow me to in an array of IDs from a table generate an ISSET to gather that information for use. How this works is a user(Captain) sees a HTML Table list of multiple people(Players). There is a "Email" button on this page that allows the user(Captain) to contact that person (Player). I do not want any personal data of the person(Player) for the user(Captain) to see. Once the user(Captain) hits the "Email" button an internal email is sent to the person(Player) with the user's(Captain's) email address. Captain's understand that only there email address will be used.

This is the code that does work:

HTML:

<table id ="example" class="tg" style="undefined;table-layout: fixed; width: 1350px">
<colgroup>
    <col style="width: 250px">
    <col style="width: 100px">
    <col style="width: 150px">
    <col style="width: 300px">
    <col style="width: 150px">
    <col style="width: 200px">
    <col style="width: 200px">
</colgroup>
<thead>
<tr>
<th class="tg-0lax">Player</th>
<th class="tg-0lax">Gender</th>
<th class="tg-cly1">Player Level</th>
<th class="tg-cly1">League</th>
<th class="tg-cly1">State</th>
<th class="tg-cly1">County</th>
<th class="tg-cly1">Contact</th>
</tr>
</thead>
<tbody>
    <?php  
       while($row3 = mysqli_fetch_array($result_plyrs))  
            { 
            ?>
<form method='POST'>
    <tr>
        <td class="tg-cly1" style="text-align:center"><?php echo $row3[0]; ?></td>
        <td class="tg-cly1" style="text-align:center"><?php echo $row3[1]; ?></td>
        <td class="tg-cly1" style="text-align:center"><?php echo $row3[2]; ?></td>
        <td class="tg-cly1" style="text-align:center"><?php echo $row3[3]; ?></td>
        <td class="tg-cly1" style="text-align:center"><?php echo $row3[4]; ?></td>
        <td class="tg-cly1" style="text-align:center"><?php echo $row3[5]; ?></td>
        <td style="text-align:center"><input type="submit" value="Email" name="<?php echo $row3[6];? 
>"></td>
</tr>
</form>
       <?php       
        }  
     ?>
</tbody>
</table>

PHP:

$sqlPlyrslkg = "Select ID, FROM wp_plyrlkg WHERE league='Adult-Team'";
$resPlyr = mysqli_query($link, $sqlPlyrslkg);
$Plyrlkg_ID = array();
while ($rowPlyrlkg = mysqli_fetch_array($resPlyr)) {
$Plyrlkg_ID[] = (int)$rowPlyrlkg[0];
}

if(isset($_POST["$Plyrlkg_ID[0]"])){{
....
}
if(isset($_POST["$Plyrlkg_ID[1]"])){{
....
}
if(isset($_POST["$Plyrlkg_ID[2]"])){{
....
}
if(isset($_POST["$Plyrlkg_ID[3]"])){{
....
}

In this case I am showing 4 possibilities, I need a way to handle possibly 100 or more possibilities. How can I do this efficiently?

BigUncleE
  • 51
  • 8
  • 1
    Use a loop... `for($i = 0; $i <= 100; $i++)` followed by `if(isset($_POST[$Plyrlkg_ID[$i]])){{ ... ` – Tim Lewis Oct 20 '20 at 15:30
  • If you need to contact "that person (Player)" - means one person, you need to send only id of this person from a form . and select all required data using this ID ( WHERE league='Adult-Team'" AND ID =posted_ID) no need to cycle through. Also would be nice if you start from using some of frameworks. You seem to use PHP7+ and your code style shows you using very old guide of old times. – Konstantin Ivanov Oct 20 '20 at 19:40
  • @KonstantinIvanov I have had no proper training of frameworks. I have a lot to learn. – BigUncleE Oct 21 '20 at 10:44
  • @TimLewis Thank you Your suggestion worked. To make it easier for me to never have to keep track of the number I included a mysql query of the Count of possibilites as a variable. – BigUncleE Oct 22 '20 at 09:40

2 Answers2

0

I think it doesn't work because you forgot the action in your form tag. Then, my advice to you is to prefere to use % instead of px. That would adapt your website if someone surf on it with a phone.

  • Hello Leo, see https://stackoverflow.com/questions/7711466/checking-if-form-has-been-submitted-php. No need for "action". Comment by Joe Pigott – BigUncleE Oct 21 '20 at 11:21
0

Here is the modified PHP that corrected my issue @TimLewis:

$sqlPlyrslkg = "Select ID FROM wp_plyrlkg WHERE league='Adult-Team'";
$resPlyr = mysqli_query($link, $sqlPlyrslkg);

$Plyrlkg_ID = array();
    while ($rowPlyrlkg = mysqli_fetch_array($resPlyr)) {
    $Plyrlkg_ID[] = (int)$rowPlyrlkg[0];
}   

$sqlPlyrCnt = "SELECT COUNT(`ID`) FROM `wp_plyrlkg` WHERE `league` = 'Adult-Team'";
$resPlyrCnt = mysqli_query($link, $sqlPlyrCnt);
$rowPlyrCnt = mysqli_fetch_array($resPlyrCnt);
$Cnt = (int)$rowPlyrCnt[0];


for ($i = 0; $i <= $Cnt; $i++){
if(isset($_POST["$Plyrlkg_ID[$i]"])){
    .....
}
}
BigUncleE
  • 51
  • 8