PHP create table then allow user to click button getting information from table
<p>I have created a HTML page and it uses PHP to take data from a database and store it into the table created. How can I get it so when the user clicks a button it will preform a certain task according to the row in the table using php?</p>

<p>I am wanting to take information from a database and create new rows in a HTML table. In those rows will be data from the database, there's also a button on each row. When the user clicks that button I want it to call a function using the specified 'name' which is represented by the variable $nam. </p>

<pre><code>&lt;?php
    ob_start();
    session_start();
    require_once 'dbconnect.php';
    if( !isset($_SESSION['user']) ) {
        header("Location: index.php");
        exit;
    }
    $deny = array("222.222.222", "333.333.333");
    if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
       header("location: http://www.google.com/");
       exit();
    }
    $res=mysqli_query($con,"SELECT * FROM users WHERE userId=".$_SESSION['user']);
    $userRow=mysqli_fetch_array($res);
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;?php header("Access-Control-Allow-Origin: http://www.py69.esy.es"); ?&gt;
    &lt;head&gt;
        &lt;title&gt;ServiceCoin&lt;/title&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
        &lt;link rel="stylesheet" href="assets/css/bootstrap.min.css" type="text/css"  /&gt;
        &lt;link rel="stylesheet" href="scripts/home/index.css" /&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;center&gt;
        &lt;h3&gt;Welcome, &lt;?php echo $userRow['userName']; ?&gt;. You Currently Have &lt;span id="services"&gt;&lt;?php echo $userRow['userServices']; ?&gt;&lt;/span&gt; Services&lt;/h3&gt;
        &lt;p id="error"&gt;&lt;/p&gt;
        &lt;button onclick="send_coins()" class="button"&gt;Send Coins&lt;/button&gt;
        &lt;button onclick="create_service()" class="button"&gt;Create A Service&lt;/button&gt;
        &lt;button onclick="send_coins()" class="button"&gt;My Services&lt;/button&gt;
        &lt;h3&gt;View Services&lt;/h3&gt;
        &lt;span&gt;&lt;?php 
        $users = 1;
        $num = 1;
        echo "&lt;center&gt;&lt;table width=1000&gt;&lt;th&gt;Buy&lt;/th&gt;&lt;th&gt;Service Name&lt;/th&gt;&lt;th&gt;Service Cost&lt;/th&gt;&lt;th&gt;Service Description&lt;/th&gt;&lt;th&gt;Service Provider Name&lt;/th&gt;";
        while($users &lt; 100 &amp;&amp; $num &lt; 100){
            $res=mysqli_query($con,"SELECT * FROM users WHERE userId=".$users);
            $userRow=mysqli_fetch_array($res);
            $id = 0;
            while($id != 10){
                $id = $id + 1;
                if($userRow['userService'.$id] === 'null'){
                }else if(!empty($userRow['userService'.$id])){
                    echo "&lt;tr&gt;&lt;td name=$num &gt;&lt;input type=submit value=buy &gt;&lt;/td&gt;&lt;td class=services width=250 align=center&gt;".$userRow['userService'.$id]."&lt;/td&gt;&lt;td class=services width=250 align=center&gt;".$userRow['userServiceCost'.$id]."&lt;/td&gt;&lt;td class=services class=services width=500 align=center&gt;".$userRow['userServiceDes'.$id]."&lt;td class=services width=500 align=center&gt;".$userRow['userServiceName'.$id]."&lt;/tr&gt;";
                    //echo $id."Error: ".$con-&gt;error;
                    $num = $num + 1;
                    $id = $id + 1;
                }
            }
            $users = $users + 1;
        }
        echo "All Services Loaded";
        echo "&lt;/table&gt;&lt;/center&gt;";
        ?&gt;&lt;/span&gt;
            &lt;span class="text-danger"&gt;&lt;?php echo $msg; ?&gt;&lt;/span&gt;
        &lt;/center&gt;
    &lt;/body&gt;
    &lt;script lang="text/javascript" src="scripts/home/index.js"&gt;&lt;/script&gt;    
&lt;/html&gt;
&lt;?php ob_end_flush(); ?&gt;
</code></pre>