PDA

View Full Version : Database Queries with links


brettpower
02-05-2007, 04:16 PM
I am not sure how to explain this, so I will do my best.

I want to have a database query, that when displayed, allows the viewer to expand the records, and then minimize them.

The data that I have in my database takes up about 4 inches of real estate so I want to condense everything down until the data needs to be viewed.


:confused:Does anybody know how or where I can read up on this?

thx.

davidj
02-05-2007, 05:34 PM
i have done this for an application i wrote except it was in the form of a nested recordset....

example...


main record1
sub record
sub record
sub record
sub record

main record2
sub record
sub record
sub record
sub record

main record3
sub record
sub record
sub record
sub record


the sub records were actually looping independantly from the main loop. infact the subs were from another table

it wont be hard to hide the subs in a hidden div or <tr>

let me think about this

davidj
02-05-2007, 09:04 PM
ok

here you are

MYSQL

# SQL Manager 2005 for MySQL 3.7.7.1
# ---------------------------------------
# Host : localhost
# Port : 3306
# Database : toolbox

SET FOREIGN_KEY_CHECKS=0;
DROP DATABASE IF EXISTS `toolbox`;
CREATE DATABASE `toolbox`
CHARACTER SET 'latin1'
COLLATE 'latin1_swedish_ci';
USE `toolbox`;
#
# Structure for the `fav_tools` table :
#
CREATE TABLE `fav_tools` (
`fav_id` int(11) NOT NULL auto_increment,
`fav_url` varchar(100) default NULL,
`fav_submited_by` varchar(30) default NULL,
`fav_review` longtext,
`fav_date_posted` date default NULL,
`fav_time_posted` time default NULL,
`fav_authorised` int(1) default NULL,
PRIMARY KEY (`fav_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
#
# Data for the `fav_tools` table (LIMIT 0,500)
#
INSERT INTO `fav_tools` (`fav_id`, `fav_url`, `fav_submited_by`, `fav_review`, `fav_date_posted`, `fav_time_posted`, `fav_authorised`) VALUES
(1,'www.page.co.uk','dj','this is a review','2007-02-05','04:00:00',NULL),
(2,'www.dwc.co.uk','dj','this is another review','2007-02-05','04:00:00',NULL),
(3,'www.dreamweaver.co.uk','dj','this is a review this is a review this is a review this is a review ','2007-02-06','09:00:00',1);
COMMIT;


Connections/connection.php

<?php
/////////////////////////////////////
$database = "toolbox";
$username = "dj";
$password = "****";
/////////////////////////////////////
$link = @mysql_connect('localhost', $username, $password);
$db = mysql_select_db($database, $link);
?>

hiddenData.php

<?php
require_once("Connections/connection.php");
$show = $_GET['show'];
if(! $_GET['toggle']){$toggle = 0;}
if($_GET['toggle'] == 0){$toggle = 1;}else{$toggle = 0;}
/////////////////////////////////////////////////
$query = sprintf("SELECT * FROM fav_tools");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
/////////////////////////////////////////////////
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="185" border="1">
<tr>
<td width="18">id</td>
<td width="151">other data </td>
</tr>

<?php

$count=1;

do{ ?>

<tr onclick="document.location.href='hiddenData.php?show=<?php echo $count; ?>&toggle=<?php echo $toggle; ?>'">
<td><?php echo $row['fav_id']; ?></td>
<td>Click here </td>
</tr>
<?php if($show == $count && $toggle == 0){?>
<tr>
<td>&nbsp;</td>
<td><?php echo $row['fav_url']; ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><?php echo $row['fav_url']; ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><?php echo $row['fav_review']; ?></td>
</tr>

<?php } ?>

<?php

$count++;

}while ($row = mysql_fetch_array($result));

?>

</table>
</body>
</html>