Hi everyone,
This is my first post on the site here. I hope I can learn from you.
I have a database with 2 tables:
// Jobs table example data
//±—±----------------------------------------------±------------±-------------±-------±---------
//| ID | description | posted_date | closing_date | filled | job_type
//±—±----------------------------------------------±------------±-------------±-------±---------
//| 41 | risus varius orci, in consequat | 2012-02-29 | 2011-09-01 | 0 | temporary
//| 42 | felis eget varius ultrices, mauris | 2011-10-10 | 2011-09-01 | 1 | temporary
//| 43 | Aenean gravida nunc sed pede. | 2012-02-01 | 2011-09-01 | 1 | permanent
//| 44 | eu erat semper rutrum. Fusce | 2012-04-15 | 2011-09-01 | 1 | temporary
//| 45 | lectus convallis est, vitae sodales | 2012-03-07 | 2011-09-01 | 0 | temporary
//| 46 | a neque. Nullam ut nisi | 2012-05-08 | 2011-09-01 | 0 | temporary
//| 47 | dignissim. Maecenas ornare egestas ligula. | 2012-01-07 | 2011-09-01 | 0 | permanent
//| 48 | eget, venenatis a, magna. Lorem | 2011-08-03 | 2011-09-01 | 0 | permanent
//| 49 | Mauris molestie pharetra nibh. Aliquam | 2011-11-02 | 2011-09-01 | 0 | permanent
// Users table example data
//±—±------------------±------------------------------------±----------±------±-------+
//| ID | name | email | job_type | level | active |
//±—±------------------±------------------------------------±----------±------±-------+
//| 61 | Dante Watts | [email protected] | temporary | 5 | 0 |
//| 59 | Jared Howard | [email protected] | permanent | 3 | 0 |
//| 60 | Herrod Roth | [email protected] | temporary | 1 | 1 |
//| 58 | Gavin Garner | [email protected] | permanent | 2 | 0 |
//| 57 | Grant Allen | [email protected] | temporary | 1 | 1 |
//| 56 | Carl Erickson | [email protected] | temporary | 4 | 0 |
It is for a jobs website. Each day I want to send a mass email to all the active users with the jobs posted that day which are still available (not filled) and match their criteria (here it is just ‘temporary’ or ‘permanent’ but this will become more detailed later (e.g. temporary jobs in the south of england).
[php]<?php
// Create an array to hold DB details
$db = array(
‘DBhost’ => ‘xxx’,
‘DBuser’ => ‘xxx’,
‘DBpass’ => ‘xxx’,
‘DBname’ => ‘xxx’
);
// Extract variables from the array
extract($db);
// Open connection to database
$connection = mysql_connect($DBhost, $DBuser, $DBpass);
if (!$connection) {
die('Could not connect ’ . mysql_error());
}
// Select the database
if (!mysql_select_db($DBname)) {
die('Could not connect ’ . mysql_error());
}
// Get today’s date in mySQL DATE format
$today = date(‘Y-m-d’);
// Get all the users who are active
$activeUsers = mysql_query(“SELECT name, email
FROM users
WHERE active = 1”);
// Get all the jobs which are still open and haven’t been filled
$newQuery = mysql_query(“SELECT name, email, description, jobs.job_type
FROM users
LEFT JOIN jobs
ON users.job_type=jobs.job_type”);
while ($row = mysql_fetch_assoc($newQuery)) {
// Something goes here I think
}
// send them an email with the job details
function getJobs($user){
// mail each user the jobs which match their requirements
}
// Close connection to database
mysql_close($connection);
?>[/php]
The above join gives me the following which is kind of what I want but now I just want each person to have an array containing their job descriptions so I can echo them out for each user in a loop:
±------------------±------------------------------------±----------------------------------------------+
| name | email | description |
±------------------±------------------------------------±----------------------------------------------+
| Dante Watts | [email protected] | risus varius orci, in consequat |
| Dante Watts | [email protected] | felis eget varius ultrices, mauris |
| Dante Watts | [email protected] | eu erat semper rutrum. Fusce |
| Dante Watts | [email protected] | lectus convallis est, vitae sodales |
| Dante Watts | [email protected] | a neque. Nullam ut nisi |
| Dante Watts | [email protected] | accumsan sed, facilisis vitae, orci. |
| Dante Watts | [email protected] | Cras eget nisi dictum augue |
| Dante Watts | [email protected] | orci. Ut sagittis lobortis mauris. |
| Dante Watts | [email protected] | Integer vulputate, risus a ultricies |
| Jared Howard | [email protected] | Aenean gravida nunc sed pede. |
| Jared Howard | [email protected] | dignissim. Maecenas ornare egestas ligula. |
| Jared Howard | [email protected] | eget, venenatis a, magna. Lorem |
| Jared Howard | [email protected] | Mauris molestie pharetra nibh. Aliquam |
Does this make any sense? Can you offer any advice?
P.S tables have been truncated to fit