jrobles Posted February 9, 2010 Share Posted February 9, 2010 hello, I am querying a table and need to email the result of my query. The results are placed in an array since I am grouping and counting data. Here is my query code $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); $row = mysql_fetch_array($result); The above query will output Product1 10 Product2 20 Product3 45 etc. I am using phpmailer and I need the array to placed inside $message i.e. $message = "QUERY ARRAY RESULTS HERE"; Any help would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/ Share on other sites More sharing options...
wildteen88 Posted February 9, 2010 Share Posted February 9, 2010 You can use arrays within a string just like you can with normal variables. Example $message = "whate ever here {$array['key1']} something else here {$array['key2']}"; Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/#findComment-1009685 Share on other sites More sharing options...
jrobles Posted February 9, 2010 Author Share Posted February 9, 2010 so i do not have to loop through the individual items? Won't your example only print the first record? Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/#findComment-1009707 Share on other sites More sharing options...
jrobles Posted February 10, 2010 Author Share Posted February 10, 2010 ? Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/#findComment-1009804 Share on other sites More sharing options...
Hussam Posted February 10, 2010 Share Posted February 10, 2010 Yes you have to loop through all of the elements to fetch them all because mysql_fetch_array() fetchs only one row at the time. Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/#findComment-1009809 Share on other sites More sharing options...
jrobles Posted February 10, 2010 Author Share Posted February 10, 2010 do you have an example? I am unsure of how to place all the array contents inside of $message Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/#findComment-1010071 Share on other sites More sharing options...
jrobles Posted February 10, 2010 Author Share Posted February 10, 2010 i tried using $message = while($row = mysql_fetch_array($result)) {echo "Product ID: $row[ProductID] Qty: $row[Count]<br>";} but that didnt work. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/#findComment-1010146 Share on other sites More sharing options...
wildteen88 Posted February 10, 2010 Share Posted February 10, 2010 i tried using $message = while($row = mysql_fetch_array($result)) {echo "Product ID: $row[ProductID] Qty: $row[Count]<br>";} but that didnt work. Any suggestions? You're close it should be $message = ''; while($row = mysql_fetch_array($result)) { $message .= "Product ID: $row[ProductID] Qty: $row[Count]<br>"; } echo $message; Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/#findComment-1010248 Share on other sites More sharing options...
jrobles Posted February 10, 2010 Author Share Posted February 10, 2010 thanks wildteen88 that worked Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/#findComment-1010271 Share on other sites More sharing options...
Hussam Posted February 10, 2010 Share Posted February 10, 2010 Yes that's exactly what I meant, perfect. sorry I was late lol. good luck. Link to comment https://forums.phpfreaks.com/topic/191536-placing-array-contents-in-email-body/#findComment-1010323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.