Hejsa.
Nu er jeg ved at få grå hår.
Jeg har to tabeller:
- CREATE TABLE IF NOT EXISTS `files` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(200) COLLATE latin1_danish_ci NOT NULL,
- `description` tinytext COLLATE latin1_danish_ci NOT NULL,
- `href` varchar(255) COLLATE latin1_danish_ci NOT NULL,
- `month` varchar(20) COLLATE latin1_danish_ci NOT NULL,
- `year` year(4) NOT NULL,
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
- `type_id` int(11) NOT NULL,
- `user_id` int(11) NOT NULL,
- `hits` int(11) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_danish_ci AUTO_INCREMENT=2 ;
-
- --
- -- Data dump for tabellen `files`
- --
-
- INSERT INTO `files` (`id`, `name`, `description`, `href`, `month`, `year`, `created`, `modified`, `type_id`, `user_id`, `hits`) VALUES
- (1, 'Juni 2011', 'Teest', 'Juni11.pdf', 'juni', 2011, '2012-03-15 00:52:18', '2012-03-14 00:09:35', 2, 1, 0);
-
-
- CREATE TABLE IF NOT EXISTS `file_type` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(50) COLLATE latin1_danish_ci NOT NULL,
- `description` varchar(255) COLLATE latin1_danish_ci NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_danish_ci AUTO_INCREMENT=3 ;
-
- --
- -- Data dump for tabellen `file_type`
- --
-
- INSERT INTO `file_type` (`id`, `name`, `description`) VALUES
- (1, 'Forsikring', 'Forsikringspapir'),
- (2, 'Lønseddel', 'Lønseddeler fra arbejdsgivere');
- <?php
- $pay = mysql_query("SELECT * FROM files WHERE type_id = '2' AND user_id = '1'") or die(mysql_error());
- while($row = mysql_fetch_assoc($pay))
- {
- echo "<tr>";
- echo "<td><input type='checkbox' /></td>";
- echo "<td>" . $row['name'] . "</td>";
- echo "<td>" . $row['description'] . "</td>";
- echo "<td>" . $row['month'] . "</td>";
- echo "<td>" . $row['year'] . "</td>";
- echo "<td>" . date('d.m.y', strtotime($row['created'])) . "</td>";
- echo "<td>" . date('d.m.y', strtotime($row['modified'])) . "</td>";
- echo "<td>" . $row['type_id'] . "</td>";
- echo "<td>" . $row['hits'] . "</td>";
- echo "<td><a href='files/paycheck/" . $row['href'] . "'>Download</a></td>";
- echo "</tr>";
- }
- ?>
Hvordan laver jeg en Join så jeg i stedet for type_id udskriver det ID der reelt står kan udskrive navnet Lønseddel?