开发者

Small table with Link to more information

开发者 https://www.devze.com 2022-12-16 06:20 出处:网络
This may be a newbie question,But let\'s say I have a database table w/ 10 fields.However, on the first screen I want a small 4-5 field table displaying corresponding data.But the first field, let\'s

This may be a newbie question, But let's say I have a database table w/ 10 fields. However, on the first screen I want a small 4-5 field table displaying corresponding data. But the first field, let's call it ID, I want to be linkable to a full table that will display complete details about that, all 10 db fields. What would the coding be...I have a friend that usually helps, but apparently this is too easy...he simply laughed at my questi开发者_如何学JAVAon.

Please help...thanks

Aaron


Is it something like this you're looking for?

First page:

<?php
// Create a connection above
$data = mysql_query('SELECT id, field2, field3, field4 FROM table') or die(mysql_error());
echo '<table>';
while($row = mysql_fetch_assoc($data))
{
  echo '<tr><td><a href="info.php?id=' . $row['id'] . '">' . $row['id'] . '</td><td>'. $row['field1'] . '</td><td>'. $row['field2'] . '</td><td>'. $row['field3'] . '</td><td>'. $row['field4'] . '</td></tr>';
}
echo '</table>';
?>

I am not sure what you want on the second page but if you want to display information about one specific row, you can do it in this way:

<?php
// Create a connection above
$data = mysql_query('SELECT * FROM table WHERE id = "' . mysql_real_escape_string($_GET['id']) . '"') or die(mysql_error());
$row = mysql_fetch_assoc($data);    
echo '<table>';
echo '<tr><td>Id:</td><td>' . $row['id'] . '</td></tr>';
echo '<tr><td>Field 1:</td><td>' . $row['field1'] . '</td></tr>';
// And so on...
?>


The first page ought to have links like:

<a href="details.php?id=1023">Item 1023</a>
<a href="details.php?id=1024">Item 1024</a>
<a href="details.php?id=1025">Item 1025</a>

Which goes to details.php:

// Very simplified - DO NOT USE AS-IS
$id = $_GET["id"]; // perhaps has the value of '1024'
$details = getDetails($id); // queries db for all data for row having id = '1024'

And on details.php you can give the specifics.

<table>
  <tbody>
    <tr>
      <td><strong>Item Name</strong></td>
      <td><strong>Item Weight</strong></td>
    </tr>
    <tr>
      <td><?php print $details->name; ?></td>
      <td><?php print $details->weight; ?></td>
    </tr>
  </tbody>
</table>
0

精彩评论

暂无评论...
验证码 换一张
取 消