travelkind Posted June 23, 2010 Share Posted June 23, 2010 I am having an issue with the query I have written as it seems to make my site "loop" back through the code and it keeps refreshing my site. I have ran a syntax check and that seems to be fine. Could someone give me an idea of where to look? Here is my code. Thanks for your input. <?php session_start(); require("config.php"); require("header.php"); require("background.php"); //Connect To Database $hostname='xxx'; $username='xxx'; $password='xxx'; $dbname='xxx'; mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); echo " ". '<br>'; $query = "SELECT Account_and_Name, YEAR(Invoice_Date) AS IYear, MONTH(Invoice_Date) AS IMonth, SUM(Ship_Quantity) AS Total, MONTHNAME(Invoice_Date) AS MName FROM rawdata WHERE Invoice_Date BETWEEN '2010-01-01' AND '2010-12-31' GROUP BY Account_and_Name, YEAR(Invoice_Date), MONTH(Invoice_Date)"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "Customer: " . $row['Account_and_Name']; echo "<br />"; ?> <html> <head> <style type="text/css"> table, td, th { border:1px solid black; } td { padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; } </style> </head> <body> <table> <tr> <th>Month</th> <th>Gallons Sold</th> <th>Sales Dollars</th> <th>Cost of Goods Sold</th> <th>Gross Profit</th> <th>Profit Per Gallon</th> </tr> </table> </body> </html> <?php echo " ". '<br>'; require("footer.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/205671-mysql-looping/ Share on other sites More sharing options...
tomtimms Posted June 23, 2010 Share Posted June 23, 2010 your while loop is before your html tag, this doesn't make any sense. try and put it after your <body> tag if you want to loop multiple tables for each customer <?PHP while($row = mysql_fetch_array($result)){ echo "Customer: " . $row['Account_and_Name']; echo "<br />"; ?> <table> <tr> <th>Month</th> <th>Gallons Sold</th> <th>Sales Dollars</th> <th>Cost of Goods Sold</th> <th>Gross Profit</th> <th>Profit Per Gallon</th> </tr> </table> <?PHP } ?> Quote Link to comment https://forums.phpfreaks.com/topic/205671-mysql-looping/#findComment-1076264 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.