SEVIZ Posted April 18, 2009 Share Posted April 18, 2009 Ok guys heres what I got! My current code is this: <?php if ($_POST["email"]<>'') { $ToEmail = $_POST["recip"]; $EmailSubject = $_POST["subject"]."\r\n"; $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = nl2br($_POST["message"]); // $MESSAGE_BODY .= ($_POST["auth"]); mail($ToEmail,$EmailSubject, $MESSAGE_BODY,$mailheader) or die ("Failure"); ?> --- <?php } else { ?> <form action="text_tool.php" method="post"> <table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td valign="top"> Send To:<br /> <?php mysql_connect("localhost", "XXXXX", "XXXXX") or die(mysql_error()); mysql_select_db("TEXT_TOOL") or die(mysql_error()); $q = "select * from sprint"; $ret = mysql_query($q); print '<select name="recip">'; while ($row = mysql_fetch_assoc($ret)) { $email_addr = $row['num']; $email_sec = $row['dept']; $domain = '@messaging.sprintpcs.com'; $email_addr .= $domain; print "<option value=\"$email_addr\">$email_sec</option>"; } ?> </select> </td> </tr> <tr> <td>Message:<br /><textarea name=message cols="20" rows="6" id="comment" maxlength="143"></textarea><br /> </td> </tr> <tr> <td> <input name="email" type="hidden" id="email" size="20" value="[email protected]"></td> </tr> <tr> <td valign="top"><font color="red" size="2"><b>Do not hit enter for a new line. This will give you less characters to use due to the text limits.</b></font><br /><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> </body> </html> <?php }; ?> Right now it queries the DB and gives me select options of all the choices in row "dept". Shows up like this: <option value="EMAIL">Tech</option> <option value="EMAIL2">Tech</option> <option value="EMAIL3">Tech</option> <option value="EMAIL4">Sup</option> <option value="EMAIL5">Sup</option> This all works great. With the above I get all 270 of my entries listed separate. But what I need to do is have it query the same info but only display a main title (based on how its listed in the db under row:"dept") and have it email all of them. So what it SHOULD look like is: <option value="EMAIL, EMAIL2, EMAIL3">Tech</option> <option value="EMAIL4, EMAIL5">Sup</option> I hope this makes sense. There are over 10 options for the main titles. Such as Tech, Sup, Mgr, HR, etc. On top of the above I need some choices to overlap. Such as this: <option value="EMAIL, EMAIL2, EMAIL3">Tech</option> <option value="EMAIL4, EMAIL5">Sup</option> <option value="EMAIL, EMAIL2, EMAIL3, EMAIL4, EMAIL5">Techs and Sups</option> I am at a loss on how to do this. Any help is appreciated as always! You guys rock! Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/ Share on other sites More sharing options...
xtopolis Posted April 18, 2009 Share Posted April 18, 2009 Well your query would likely change to something SIMILAR to: $q = "SELECT GROUP_CONCAT(DISTINCT email SEPARATOR ', ') FROM sprint GROUP BY dept"; As far as I can guess. But there are length limitations to this method. http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat Perhaps someone can post a non-limited version, maybe using subqueries or something Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-812912 Share on other sites More sharing options...
SEVIZ Posted April 18, 2009 Author Share Posted April 18, 2009 Not sure if that does everything needed though. Like setting more groups which are combinations of other groups. Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-812946 Share on other sites More sharing options...
xtopolis Posted April 18, 2009 Share Posted April 18, 2009 Am, sorry, I didn't read fully. However, you might be able to use PHP to combine the now grouped categories, right? The dataset would come out as: [dept][email,email] And so when you build the list in php, you could modify the select <options> how you wanted. Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-812954 Share on other sites More sharing options...
SEVIZ Posted April 18, 2009 Author Share Posted April 18, 2009 I tried the above but no data appears at all. Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-812978 Share on other sites More sharing options...
xtopolis Posted April 18, 2009 Share Posted April 18, 2009 Well, I can't really help you.. I don't know your table structure.. Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-813021 Share on other sites More sharing options...
SEVIZ Posted April 18, 2009 Author Share Posted April 18, 2009 Anyone else got any ideas? Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-813147 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 <?php mysql_connect("localhost", "XXXXX", "XXXXX") or die(mysql_error()); mysql_select_db("TEXT_TOOL") or die(mysql_error()); if (!empty($_POST["email"])) { $q = "select `num` from sprint WHERE `dept` = '".mysql_real_escape_string($_POST["email"])."'"; $ret = mysql_query($q); $emails = array(); while ($row = mysql_fetch_assoc($ret)) { $emails[] = $row['num'].'@messaging.sprintpcs.com'; } if ($emails) { $ToEmail = implode(', ', $emails); $EmailSubject = $_POST["subject"]."\r\n"; $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = nl2br($_POST["message"]); // $MESSAGE_BODY .= ($_POST["auth"]); mail($ToEmail,$EmailSubject, $MESSAGE_BODY,$mailheader) or die ("Failure"); } } ?> --- <?php } else { ?> <form action="text_tool.php" method="post"> <table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td valign="top"> Send To:<br /> <?php $q = "select `dept` from sprint GROUP BY `dept`"; $ret = mysql_query($q); print '<select name="recip">'; while ($row = mysql_fetch_assoc($ret)) { $email_sec = $row['dept']; print "<option value=\"$email_sec\">$email_sec</option>"; } ?> </select> </td> </tr> <tr> <td>Message:<br /><textarea name=message cols="20" rows="6" id="comment" maxlength="143"></textarea><br /> </td> </tr> <tr> <td> <input name="email" type="hidden" id="email" size="20" value="[email protected]"></td> </tr> <tr> <td valign="top"><font color="red" size="2"><b>Do not hit enter for a new line. This will give you less characters to use due to the text limits.</b></font><br /><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> </body> </html> <?php }; ?> EDIT: Fix typo Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-813272 Share on other sites More sharing options...
SEVIZ Posted April 18, 2009 Author Share Posted April 18, 2009 Thanks for the help but I get a parse error on line 25. unexpected } Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-813275 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 Lose the closing bracket here so that: <?php } else { ?> becomes <?php else { ?> Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-813276 Share on other sites More sharing options...
SEVIZ Posted April 18, 2009 Author Share Posted April 18, 2009 Error changes now to: unexpected T_ELSE on line 25. Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-813278 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 That's what comes with not using an editor ;-) <?php mysql_connect("localhost", "XXXXX", "XXXXX") or die(mysql_error()); mysql_select_db("TEXT_TOOL") or die(mysql_error()); if (!empty($_POST["email"])) { $q = "select `num` from sprint WHERE `dept` = '".mysql_real_escape_string($_POST["email"])."'"; $ret = mysql_query($q); $emails = array(); while ($row = mysql_fetch_assoc($ret)) { $emails[] = $row['num'].'@messaging.sprintpcs.com'; } if ($emails) { $ToEmail = implode(', ', $emails); $EmailSubject = $_POST["subject"]."\r\n"; $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = nl2br($_POST["message"]); // $MESSAGE_BODY .= ($_POST["auth"]); mail($ToEmail,$EmailSubject, $MESSAGE_BODY,$mailheader) or die ("Failure"); echo 'Message sent'; } } else { ?> <form action="text_tool.php" method="post"> <table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td valign="top"> Send To:<br /> <?php $q = "select `dept` from sprint GROUP BY `dept`"; $ret = mysql_query($q); print '<select name="recip">'; while ($row = mysql_fetch_assoc($ret)) { $email_sec = $row['dept']; print "<option value=\"$email_sec\">$email_sec</option>"; } ?> </select> </td> </tr> <tr> <td>Message:<br /><textarea name=message cols="20" rows="6" id="comment" maxlength="143"></textarea><br /> </td> </tr> <tr> <td> <input name="email" type="hidden" id="email" size="20" value="[email protected]"></td> </tr> <tr> <td valign="top"><font color="red" size="2"><b>Do not hit enter for a new line. This will give you less characters to use due to the text limits.</b></font><br /><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> </body> </html> <?php } Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-813285 Share on other sites More sharing options...
SEVIZ Posted April 18, 2009 Author Share Posted April 18, 2009 Genius! It worked so far flawlessly! Now all I need to figure out is how to add a choice for combinations. Thanks again! It is appreciated more than you know! Link to comment https://forums.phpfreaks.com/topic/154584-solved-group-query-not-list-them-seperate-and-choose-how-to-group/#findComment-813289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.