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 Quote Link to comment 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']}"; Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
jrobles Posted February 10, 2010 Author Share Posted February 10, 2010 ? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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; Quote Link to comment Share on other sites More sharing options...
jrobles Posted February 10, 2010 Author Share Posted February 10, 2010 thanks wildteen88 that worked Quote Link to comment 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. Quote Link to comment 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.