Create links with records and mysql page data from link

User avatar
JanMolendijk
Posts: 80
Location: Holland Rotterdam

Create links with records and mysql page data from link

Into this code i see 30 records.
Now i wanna add a link to eatch single record.
i can do this with: >'. $row['notice_id'] .'
but how do i create a singel page with all info from one sigle record?

Code: Select all

<?php
include('../connection.php');

$sql=mysqli_query($conn,"SELECT * FROM `notice` ORDER BY `notice`.`notice_id` DESC LIMIT 30");

$rehtm='';
// if the $sql contains at least one row
if(mysqli_num_rows($sql) >0){
  //get rows data
  while($row = mysqli_fetch_assoc($sql)){
    $rehtm .='<table class="table table-bordered">
   <Tr class="success">
      <th>'. $row['notice_id'] .' '. $row['Date'] .'</th>
      <th>Title: '. $row['subject'] .'</th>
      </Tr><Tr><td><br>
 '. $row['Description'] .'</td></Tr><br><br><br> ';
  }
}
else {
  $rehtm .='0 results';
}

echo $rehtm;
?>

Admin
Hello
Create for each reccord a link to a php file, that contains the record ID.

Code: Select all

$link ='<a href="page.php?id='.$row['notice_id'].'" title="'.$row['subject'].'">'.$row['subject'].'</a>';

Put the $link in $rehtm, where you want to be displayed.
Then, in "page.php" get the id from the url address (with $_GET['id']), and make a mysql select with that id:
- page.php:

Code: Select all

$repg ='no valid id';
if(isset($_GET['id'])){
  include('../connection.php');
  $id = intval($_GET['id']);
  $sql=mysqli_query($conn,"SELECT * FROM `notice` WHERE notice_id =$id LIMIT 1");
  if(mysqli_num_rows($sql) >0){
    while($row = mysqli_fetch_assoc($sql)){
      $repg = $row['Description'];
    }
  }
  else $repg ='No page data';
}

echo $repg;

JanMolendijk
One Question when i do this
<?php echo $row['notice_id'];?>
i don`t see the notice_id ?

I`m gonna use this id for your comment-tree

Code: Select all

<?php

$repg ='no valid id';
if(isset($_GET['id'])){
  include('../connection.php');
  $id = intval($_GET['id']);
  $sql=mysqli_query($conn,"SELECT * FROM `notice` WHERE notice_id =$id LIMIT 1");
  if(mysqli_num_rows($sql) >0){
    while($row = mysqli_fetch_assoc($sql)){
      $repg = $row['Description'];
    }
  }
  else $repg ='No page data';
}

echo $repg;

?>
<?php echo $row['notice_id'];?>


Admin
If there is a "notice_id"; in that mysql table, you can store it in a variable, then apply "echo" to that variable.

Code: Select all

while($row = mysqli_fetch_assoc($sql)){
  $notice_id = $row['notice_id'];
}
//etc.. your code
echo isset($notice_id) ?$notice_id :0;

Adv. Posts: 01

Similar Topics