0

i have 2 html table one is table.php and anther one is viewdata.php. In frist table there arenumber of rows and data is extracting from mysql database. If i will click on serial no 1 of my html table data then the detail of serial no 1 must show in another table and i tried so. But i dont understand how to do it.

table.php this is the html table

<?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass)
         or die ('Error connecting to mysql');

    $dbname = 'form_db';
    mysql_select_db($dbname);
    $query = "SELECT * FROM form";
    $result = mysql_query($query) 
              or die(mysql_error()); 
    print " 
        <table id=\"AutoNumber2\" border=\"1\">
            <tr>
                <th>S.no</th>
                <th>Title of thesis:</th>
                <th>View detail:</th>
            </tr>";

    while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
        print "<tr>"; 
        print "<td>" . $row['s_no'] . "</td>"; 
        print "<td>" . $row['title of thesis'] . "</td>"; 
        print "</tr>"; 
    } 
    print "</table>"; 
?>

dataview.php another table

<?php
    $query = "SELECT * FROM form";
    $result3 = mysql_query($query) 
               or die(mysql_error()); 

    $result3 = mysql_query("SELECT * FROM form where s_no='11'");
    while($row3 = mysql_fetch_array($result3, MYSQL_ASSOC)){ 
        $s_no=$row3['s_no'];
        $obs_time=$row3['obs_time'];
        $title=$row3['title'];
        $type=$row3['type'];
        $thesis=$row3['thesis'];
        $year=$row3['year'];
        $proposer=$row3['proposer'];
        $institute=$row3['institute'];
        $email=$row3['email'];
        $present=$row3['present'];
        $date=$row3['date'];
    }
?>

Here I have mannualy select the s_no'11'. I dont know how i can pass the s_no automatically simply clicking on the row (view detail) which i want to show in another table with its detail. thank you so much./!!

masud_moni
  • 1,121
  • 16
  • 33
REZTO
  • 35
  • 3

1 Answers1

1

send the variable via the URL using $_GET

dbconnect.php

<?php 
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');

    $dbname = 'form_db';
    mysql_select_db($dbname);?>

table.php

    include('dbconnect.php'); 
    $query = "SELECT * FROM form";
    $result = mysql_query($query) or die(mysql_error()); 
    print " 
        <table id=\"AutoNumber2\" border=\"1\">
            <tr>
                <th>S.no</th>
                <th>Title of thesis:</th>
                <th>View detail:</th>
            </tr>";

    while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
        print "<tr>"; 
        print "<td><a href=\"dataview.php?s_no=".$row['s_no']. \"\">". $row['s_no'] . "</a></td>"; 
        print "<td>" . $row['title of thesis'] . "</td>"; 
        print "</tr>"; 
    } 
    print "</table>";?>

dataview.php

<?php
    include('dbconnect.php'); 
    $sn= $_GET['s_no'];
    $sql = "SELECT * FROM form where s_no=". $sn;
    $result3 = mysql_query($sql);
    while($row3 = mysql_fetch_array($result3, MYSQL_ASSOC)){ 
        $s_no=$row3['s_no'];
        $obs_time=$row3['obs_time'];
        $title=$row3['title'];
        $type=$row3['type'];
        $thesis=$row3['thesis'];
        $year=$row3['year'];
        $proposer=$row3['proposer'];
        $institute=$row3['institute'];
        $email=$row3['email'];
        $present=$row3['present'];
        $date=$row3['date'];
    }
?>
Schnecke
  • 502
  • 1
  • 6
  • 18