1

noob here. I am trying to create a table where I can put in separate buttons that link to my next .php page and to certain information from the next page tables. I have tried for hours and hours to get a style of table pdo that will allow me to add my own separate buttons with link to my next .php page.

But without adding one input href that creates a button for all of the rows.

Unless there is a way to add it to the single href section. But I have no idea. The links work but just point to the next page as a whole instead of choosing a table.

There are 3 tables on the next .php page, taken from mysql databases. Here is my index.php page. It is just basic for now until I can get the php code to work. I take it there is something to do with superglobals or sessions?? Thanks in advance.

   <html>
   <head>
   <title>Blah</title>
   <H1>Blah</H1>
   <H2>Blah</H2>

   <body>
   <?php
   include 'mystyles.css';
   ?>
   <?php
   $user = '123';
   $pass = '456';
   $db = new PDO( 'mysql:Myhost;dbname=123', $user, $pass );
   $sql = "SELECT * FROM Production";
   $query = $db->prepare( $sql );
   $query->execute();
   $results = $query->fetchAll( PDO::FETCH_ASSOC );

   ?>
   <table class="table">
   <tr>
   <th>Title</th>
   <th>Ticket Cost</th>
   <th></th>
   <?php 
   foreach( $results as $row ){
    echo "<tr><td>";
    echo $row['Title'];
    echo "</td><td>";
    echo $row['BasicTicketPrice'];
    echo ('<td><a href="perf.php"><input type="submit" name="submit" 
    value="Register" class="register" /></a></td>');
    echo "</tr>";
    }

    ?>
    </table>
    </body>
    </html>
Bob Hope
  • 1
  • 6

1 Answers1

0

One way is You need to pass the value to next page via GET ie in the URL

For eg:

<a href="perf.php?id=".$row['TicketId']."">.... </a>
This will result like <a href="perf.php?id=2">...... </a>

Once user clicks the link value will be passed to next page via GET, u can u use that value for computation

Sample

<html>
   <head>
   <title>Blah</title>
   <H1>Blah</H1>
   <H2>Blah</H2>

   <body>
   <?php
   include 'mystyles.css';
   ?>
   <?php
   $user = '123';
   $pass = '456';
   $db = new PDO( 'mysql:Myhost;dbname=123', $user, $pass );
   $sql = "SELECT * FROM Production";
   $query = $db->prepare( $sql );
   $query->execute();
   $results = $query->fetchAll( PDO::FETCH_ASSOC );

   ?>
   <table class="table">
   <tr>
   <th>Title</th>
   <th>Ticket Cost</th>
   <th></th>
   <?php 
   foreach( $results as $row ){
    echo "<tr><td>";
    echo $row['Title'];
    echo "</td><td>";
    echo $row['BasicTicketPrice'];
    echo ('<td><a href="perf.php?id=".$row['TicketId'].""><input type="submit" name="submit" 
    value="Register" class="register" /></a></td>');
    echo "</tr>";
    }

    ?>
    </table>
    </body>
    </html>
Mahesh Hegde
  • 1,131
  • 10
  • 12