Jump to content

MYSQL Looping?


travelkind

Recommended Posts

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");

}

?>

 

Link to comment
Share on other sites

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 } ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.