/    Sign up×
Community /Pin to ProfileBookmark

JOIN table with with dates and item_id

Hi

next little issue

I have successfully joined two tables together and got the data pulled in from the two tables, now I need to pull data from a third table that contains 3 different dates for different item_id numbers so one is car mot date, second is car insurance date and the third is car tax date

The code I put in profile.php is below

[code=php]
$sql = “SELECT * FROM users INNER JOIN visitors on visitors.visitor_id = visitors.visitor_id INNER JOIN renewal on visitors.visitor_id = visitors.visitor_id WHERE users.id = $id LIMIT 1”;
then bit further below, I have the echo code

echo “<p>Car MOT Expiry Date: {$user[‘renewal_date’]}</p>”;
echo “<p>Car Insurance Expiry Date: {$user[‘renewal_date’]}</p>”;
echo “<p>Car TAX Expiry Date: {$user[‘renewal_date’]}</p>”;
[/code]

obviously that just outputs the same date on each row

my database structure for the renewal table is below

— phpMyAdmin SQL Dump
— version 4.0.7

[url]http://www.phpmyadmin.net[/url]

— Host: localhost
— Generation Time: Jun 29, 2015 at 09:46 AM
— Server version: 5.5.42
— PHP Version: 5.3.28

SET SQL_MODE = “NO_AUTO_VALUE_ON_ZERO”;
SET time_zone = “+00:00”;

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

— Database: `databasename`


— ——————————————————–

— Table structure for table `renewal`

CREATE TABLE IF NOT EXISTS `renewal` (
`renewal_id` int(11) NOT NULL AUTO_INCREMENT,
`visitor_id` int(11) NOT NULL,
`item_id` int(11) NOT NULL,
`renewal_date` date NOT NULL,
`date_notified` datetime DEFAULT NULL,
PRIMARY KEY (`renewal_id`),
KEY `renewal_id` (`renewal_id`),
KEY `renewal_id_2` (`renewal_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=181 ;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @ianhaney spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...