andz Posted August 19, 2007 Share Posted August 19, 2007 I have these tables and sample contents: jobs_table id, title, catid, content 1, first title, 1, first content 2, second title, 1, second content 3, third title, 2, third content 4, fourth title, 2, fourth content category_table catid, name 1, first category 2, second category users_table email, name, catid test@localhost.com, test user, 1~2 test2@localhost.com, test2 user, 1 test3@localhost.com, test3 user, 2 test4@localhost.com, test4 user, 1~2 I already knew how to make the catid in users_table readable. I'm trying to send an email. The email contains the job title of the jobs linked by the catid the users choose. My problem is that, how can I load all the users and the same time the job information to be ready for the email? The expected output will be: mail(); test@localhost.com first title second title third title fourth title mail(); test2@localhost.com first title second title mail(); test3@localhost.com third title fourth title mail(); test4@localhost.com first title second title third title fourth title Anyone could help me with this??? IF possible with source code. Quote Link to comment https://forums.phpfreaks.com/topic/65673-need-help-on-fetching-information-and-email/ Share on other sites More sharing options...
sasa Posted August 19, 2007 Share Posted August 19, 2007 try <?php mysql_connect('localhost'); mysql_select_db('test'); $sql = 'SELECT email, catid FROM users_table'; $result = mysql_query($sql); $emails = array(); while ($row = mysql_fetch_array($result)){ $tmp = array(); $tmp['email'] = $row['email']; $sql = 'SELECT title FROM jobs_table WHERE catid IN ('. implode(', ',explode('~', $row['catid'])). ')'; $result1 = mysql_query($sql); while ($row1 = mysql_fetch_array($result1)){ $tmp['contest'][] = $row1['title']; } $emails[] = $tmp; } foreach ($emails as $email) { echo 'Email:',$email['email'],"<br />\n",implode("<br />\n",$email['contest']),'<hr />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65673-need-help-on-fetching-information-and-email/#findComment-327978 Share on other sites More sharing options...
andz Posted August 19, 2007 Author Share Posted August 19, 2007 Thanks for the reply. I'll give it a shot. Could I email you incase I have a question??? Quote Link to comment https://forums.phpfreaks.com/topic/65673-need-help-on-fetching-information-and-email/#findComment-327988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.