dplatt dplatt - 7 months ago 11
SQL Question

PHP $_GET from HTML table row

so I have a table of data that gets produced in PHP. What I was hoping for, would be to have a button to view that specific piece of data in that table row, i.e. press 'view graph' and it uses the $_GET method to take the id of the value of that row, and use it to display data. This instead of creating an individual page for each graph, so it just produces the relevant data for that page.

At the moment, my code looks like this:

if ($id==$server_id){
echo("<tr><td>".$row2['hostname']."</td>
<td><a href=".$url.">".$row['name']."</a></td>
<td><span class='label label-$alerting'>"
.$row['capacity'].
"%</span></td>
<td><input type='submit' value='View Graph'></td>
</form></tr>");
}


How would I get the id/name for each row to parse into a new page?

Answer

You can create with the url/argument:

if ($id==$server_id){
    echo("<tr><td>".$row2['hostname']."</td>
    <td><a href=".$url.">".$row['name']."</a></td>
    <td><span class='label label-$alerting'>"
    .$row['capacity'].
    "%</span></td>
    <td><a href='yourUrl?id=".$row['id']."'>View Graph</a></td>
    </tr>");
}