jrobles Posted February 10, 2010 Share Posted February 10, 2010 $qry ="SELECT ProductID, SUM(QtyOrdered) AS Count FROM OrderHeader_1 JOIN OrderDetail ON OrderHeader_1.OrderID = OrderDetail.OrderID WHERE OrderHeader_1.OrderID = $oid GROUP BY ProductID"; $result = @mysql_query($qry); $rows = mysql_fetch_array($result); returns: ProductID Count 1 7 3 2 how can I place the array contents in $message so I can email the query results using phpmailer Quote Link to comment https://forums.phpfreaks.com/topic/191653-need-array-help/ Share on other sites More sharing options...
jskywalker Posted February 10, 2010 Share Posted February 10, 2010 <?php $a=array('1' => '1', '2' => '2', '3' => '3', '4'=>'4'); $message=""; for ($x = 1; $x <= count($a); $x++) { $message.=$a[$x]; } echo $message; ?> Quote Link to comment https://forums.phpfreaks.com/topic/191653-need-array-help/#findComment-1010236 Share on other sites More sharing options...
premiso Posted February 10, 2010 Share Posted February 10, 2010 $message = "ProductID\tCount\n"; while ($rows = mysql_fetch_assoc($result)) { $message .= "{$rows['ProductID']}\t{$rows['Count']}\n"; } Should do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/191653-need-array-help/#findComment-1010238 Share on other sites More sharing options...
jrobles Posted February 10, 2010 Author Share Posted February 10, 2010 thanks for your help guys, but its not working quite right. premiso's code returned: ProductID Count 1 7 3 2 jskywalker's code returned: 7 Quote Link to comment https://forums.phpfreaks.com/topic/191653-need-array-help/#findComment-1010260 Share on other sites More sharing options...
wildteen88 Posted February 10, 2010 Share Posted February 10, 2010 premiso's code does exactly what you're wanting to do. How are you outputting $message variable? Quote Link to comment https://forums.phpfreaks.com/topic/191653-need-array-help/#findComment-1010266 Share on other sites More sharing options...
jrobles Posted February 10, 2010 Author Share Posted February 10, 2010 im using $message as the email body for phpmailer Quote Link to comment https://forums.phpfreaks.com/topic/191653-need-array-help/#findComment-1010273 Share on other sites More sharing options...
premiso Posted February 10, 2010 Share Posted February 10, 2010 Are you sending the email as HTML? If so a modification to my code would be: $message = "<table><tr><td>ProductID</td><td>Count</td></tr>"; while ($rows = mysql_fetch_assoc($result)) { $message .= "<tr><td>{$rows['ProductID']}</td><td>{$rows['Count']}</td></tr>"; } $message .= "</table>"; Which should send properly as html. Quote Link to comment https://forums.phpfreaks.com/topic/191653-need-array-help/#findComment-1010285 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.