How to create a new page from a clickable row table

Codes here !

Moderators: egami, macek, gesf

Post Reply
Adrian
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Mar 12, 2017 9:47 am

Sun Mar 12, 2017 9:50 am

I have a problem and i can't find any solution on the internet. So i have a db with about 20 columns. I print from this db only 5 columns for a preview like this:

Code: Select all

<?php
$host    = "localhost";
$user    = "user";
$pass    = "";
$db_name = "db_test";

//create connection
$connection = mysqli_connect($host, $user, $pass, $db_name);

//test if connection failed
if(mysqli_connect_errno()){
    die("connection failed: "
        . mysqli_connect_error()
        . " (" . mysqli_connect_errno()
        . ")");
}

//get results from database
$result = mysqli_query($connection,"SELECT id,first,sec,school,data FROM test");
$all_property = array();  //declare an array for saving property

//showing property
echo '<table class="data-table" border ="1">
        <tr class="data-heading">';  //initialize table tag
while ($property = mysqli_fetch_field($result)) {
    echo '<td>' . $property->name . '</td>';  //get field name for header
    array_push($all_property, $property->name);  //save those to array
}
echo '</tr>'; //end tr tag

//showing all data
while ($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    foreach ($all_property as $item) {
        echo '<td>' . $row[$item] . '</td>'; //get items using property value
    }
    echo '</tr>';
}
echo "</table>";
?>
After the table is print, I want when click is press to create a new page with all the records from the db for that specific id. I have search over the internet but i can't find any solution. Can anyone help me ?:) Thanks in advice.

chorn
php-forum Active User
php-forum Active User
Posts: 405
Joined: Fri Apr 01, 2016 2:18 am

Mon Mar 13, 2017 10:57 pm

link

Code: Select all

foo.php?bar=123
php

Code: Select all

$pdo = new PDO(...);
$stmt = $pdo->prepare('select x, y, z from foo where bar = ?');
$stmt->execute([$_GET['bar']]);
var_dump($stmt->fetchAll());

Post Reply