Farhad paikan Farhad paikan - 5 days ago 5
MySQL Question

Retrieve data from mysql database and insert it in a table using php

I design 3 pages in html with bootstrap framework, one is i can insert data to database the second it shows subject and date of the data i inserted in database in a html table and i want the 3rd page to get data from database when i click on recorded data in table and show it in the 3rd page.

|-------|----------|--------------|
| No | Subject | Date |
|-------|----------|--------------|
| 1 | A | 2016 |
|-------|----------|--------------|
| 2 | B | 2016 |
|-------|----------|--------------|


when i click on A i want to get data about A project from Database and when i click on B i want to get details about B project in another Page from databse.

i don't have any idea how to do that with php and html.

sorry for bad English

Answer

Pass Project No with GET Variable and retrieve that data with that ID in 3rd page like this :

Second Page :

<tr>
    <td><?=$project->no;?></td>
    <td><?=$project->subject;?></td>
    <td><a href="localhost/3rdpage.php?id=<?=$project->no;?>">Details</a></td>
</tr>

Third Page :

$projectNo = $_GET['id'];

$stmt = $pdo->prepare('SELECT * FROM project WHERE no = ?');
$stmt->execute(array($projectNo));
$data = $stmt->fetch(PDO::FETCH_OBJ);
Comments