i created main.php page. this page includes these following php codes,

<?php
$user = "";
$pass = "";
$db = "";
$connect = mysql_connect("", $user, $pass);
if(!$connect)
{
    die ("Could not connect to MySQL");
}
mysql_select_db($db, $connect) or die ("Could not open $db: " .mysql_error());
$sql = mysql_query ( "SELECT slno, refno, gname, aname, dob, cid, cod, status FROM add_details" );
$num_rows = mysql_num_rows( $sql );
print "<table border=1 align=center cellpadding=8>\n";
print "<tr>\n";
print "<th>Serial No</th>";
print "<th>Reference No</th>";
print "<th>Guest Name</th>";
print "<th>Agent Name</th>";
print "<th>Date of Booking</th>";
print "<th>Check in Date</th>";
print "<th>Check out Date</th>";
print "<th>Status</td>";
print "<th>Generate Bill</td>";
print "</tr>\n";
while($a_row = mysql_fetch_row($sql))
{
    print "<tr>\n";
    foreach($a_row as $field)
    print "\t<td>$field</td>\n";
    print "</tr>\n";
}
print "</table>\n";
mysql_close($connect);
?>

this coding fetch all details from database perfectly. but when i click one value (like gname) it should be show all details of that specific row in new tab. in my db includes 20+ fields. please if anyone know help me. i'm just a beginner...

You'll have to create a link to a page that shows the details, by passing it an ID.

how to do that? can u pls give me some example?

First try to create a new script that gets an ID via $_GET to show all details of a single row.

First off, you've created 9 <th>s but have only 8 fields you're pulling from the DB. You're not outputting anything to your Generate Bill column.

My recommendation is rather than a foreach loop for outputting your fields, do it the long way. I.e.,

// Inside your loop...
print "<tr>\n";
print "\t<td>$a_row['slno']</td>\n";
print "\t<td>$a_row['refno']</td>\n";
//etc., etc. Don't forget your Generate Bill column!
print "</tr>\n";

Now it's also easier to follow pritaeas' advice. Decide which column in your table you want to contain the clickable link to go to the View page. You might use the Serial No column, for example.

// replace the "slno" line I put above with:
print "\t<td><a href='/view.php?id=$a_row['slno']'>$a_row['slno']</a></td>\n";

That done, you create a script called view.php and add a line with:

if(isset($_GET['id'])) {
    $id = (num) mysql_real_escape_string($_GET['id']);
    // Add to code to search your database for an entry with this serial number
}

in my generate bill column i need to put a simple button and then if we click that it should show all details of specific row.. that is my idea.. but, is there any way to do that?
1. i added user details (20+ values)
2. then i retrieved the few (6) values from db but. in that generate bill column i want to add the button when we update the page. instead of clicking any specific field i want to put a button in that column. so only... is there any way to do that?

thanks to both of u. now i got what i wanted. ur comments given me some good ideas so i searched on the web and cleared it...
but, i need to know lot of things in php..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.