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>";
//}
?>

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.