0

I have an HTML table populated from a mysql database table via PHP with 8 different values. I need to open a second page and pass to it any one from the values I click on in order to query another from the database. So far I can open the second page via href but I could solve the parameter issue. Can anyone help me on this?

The code:

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

    <?php
    include "ligabd.php";//connects to the server
    if(!$l)
    {
        die("Ligação sem sucesso: ".mysql_error());
    }
    else
    {            
        $query="SELECT escalao FROM escaloes ORDER BY idescaloes ASC";
        $result=  mysqli_query($l, $query);                       
    ?>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <table id="t01" align="center">
     <br>
     <br>
     <br>
     <br>
     <tr>
      <td align="center">Escalões</td>
      </tr>

    <?php
        while ($record=  mysqli_fetch_array($result))
        {
            $r=$record['escalao'];
            ?>
            <tr>
            <td>
            <a href="pag_escalao_mensalidade.php?escalao=">
            <?php 
            echo $record['escalao'];
            ?>
            </a>
            </td>
            </tr>
            <?php
        }                       
    }
    ?>
    </table>
</body>

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Possible duplicate of [simple php pagination](http://stackoverflow.com/questions/3705318/simple-php-pagination) – Clarkie Dec 02 '15 at 18:34

2 Answers2

1

You should use id in your table and use this:

$query="SELECT id, escalao FROM escaloes ORDER BY idescaloes ASC";
...
while ($record=mysqli_fetch_assoc($result))  // Fetch assoc!
...
<a href="pag_escalao_mensalidade.php?id=<?= $record['id'] ?>"><?= $record['escalao'] ?></a>
....

On the second page, you fetch the record again

$query='SELECT * FROM escaloes WHERE id=' . intval( $_GET['id'] );
Hasse Björk
  • 1,431
  • 13
  • 19
0

This is wrong:

<a href="pag_escalao_mensalidade.php?escalao=">
<?php 
echo $record['escalao'];
?>

It should be

    <a href="pag_escalao_mensalidade.php?escalao=<?php 
                                                 ^^---
    echo $record['escalao'];
    ?>"><?php echo $record['escalao'] ?>
      ^^^^^^^---

Note the indicated changes

Marc B
  • 356,200
  • 43
  • 426
  • 500