Jump to content

Displaying columns in table using php


ramyakumar

Recommended Posts

Hello,

I am trying to display a music table using mysql and php. I have a music table with categories and other data like name, price, category, singers. I want to display categories of the music that $music and the number of cds in that category is $no. I am not able to display the number of dvds in correspond with the category. It is showing me all the counts in a single line in each row. It is repeating the count in all the rows.  this is the query and code

$query = "SELECT DISTINCT category, COUNT(*) AS num_dvds from dvds GROUP BY category";

 

echo '<table>';
foreach ($music as $v) {
echo '<tr>';
echo '<td><input type="checkbox"></td>';
echo '<td>' . $v . '</td>';
   foreach ($num_dvds as $no) 
echo '<td>' . $no . '</td>';
echo '</tr>';
}
echo '</table>';

 

I think it is problem of the arranging of foreach or the braces but I tried many ways and nothing worked for me. Could anyone help me please?

 

 

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.