Jump to content

Pulling from database, using row data as a header (category)


phpstuck

Recommended Posts

Ok here's my problem. I am running an inventory database (MySQL) using PHP to generate several different reports.

 

I have a row in my table named CAT, I would like to generate a report using the CAT as a header. It would pull a CAT name from the table, echo it as a header and then list each item with that particular CAT name.

 

making it look like this:

 

Canned Food:

 

Kroger, Sweet Corn  11 Cans

Kroger, Early Peas    13 Cans

etc...

 

Boxed Food:

 

Kraft, Mac & Cheese      24 Boxes

Kroger, Saltine Crackers  8 boxes

etc...

 

Where as canned foods and boxed foods are CAT (category) entries from the database.

 

I have tried using the following code, but it falls very short.

 

$sql = mysql_query(
"ALTER TABLE inven ORDER BY cat");




echo "<br><hr>";


$deflist=mysql_query(
        "SELECT quant, brand, descrip, size, flavor, cat FROM inven");

while ($all = mysql_fetch_array($deflist)) {
  $quant=$all['quant'];
  $brand=$all['brand'];
  $descrip=$all['descrip'];
  $size=$all['size'];
  $flavor=$all['flavor'];
  $cat=$all['cat'];

//{ echo "<p>".$cat."</p>"; }

//echo "<b><font face='arial' size='2'><u>(".$quant.
//") </b></font></u><font face='arial' size='2'>".$brand.", ".
//" - "."<font color='grey' size='-1'><i>".$descrip." - ".$flavor.
//"</i></font> - <i><font color='purple' size='-3'></i>".$size.
//"</font><br>";
//}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.