Jump to content

expanded count problem


mescal

Recommended Posts

Hi,

 

I have this table netcat where i have a discipline, a category and items

i want to make a searchpage where u can find per discipline the different categories and per categories the count of items (this doesn't work, grrr)

can someone help??

 

thx in advance

mescal

 

this is my code

$query_discipline="SELECT DISTINCT discipline FROM netcat ORDER BY discipline DESC ";

$result_discipline=mysql_query($query_discipline);

// Define the colours for the alternating rows

$colour_odd = "#FFF2BF";

$colour_even = "#FFE680";

$row_count = 0;  //To keep track of row number

 

echo '<table width="90%" border="0" cellpadding="1" cellspacing="2">';

// Fetch the array of records and Loop through them

while ($row_discipline=mysql_fetch_array($result_discipline)){

$discipline_choice=$row_discipline['discipline'];

//discipline choice

switch ($discipline_choice){

case AU:

$display_head= $cars;

break;

case MO:

$display_head= $models;

break;

case PB:

$display_head= $bears;

break;

case BL:

$display_head= $blik;

break;

default:

$display_head= $trains;

}

 

/* Echo the table row and table data that needs to be looped over until the end of the recordset*/

echo '<th>'.$display_head.'</th>';

 

$query_categorie="SELECT DISTINCT categorie FROM netcat WHERE discipline='$discipline_choice' ORDER BY categorie ASC ";

$result_categorie=mysql_query($query_categorie);

while ($row_categorie=mysql_fetch_array($result_categorie)){

$display_cat=stripslashes($row_categorie[categorie]);

// Decide which colours to alternate for the rows

// If Remainder of $row_count divided by 2 == 0.

$row_color = (($row_count % 2) == 0) ? $colour_even : $colour_odd;

echo'<tr bgcolor="'.$row_color.'">

<td width="300" align="left"><b><nobr>'.$display_cat.'</nobr></b></td></tr>';

$query="SELECT COUNT(*) AS num FROM netcat WHERE discipline='$discipline_choice' AND categorie='display_cat'";

$result=mysql_query($query);

echo $query;

while ($row=mysql_num_rows($result)){

echo'<td width="300" align="left"><b><nobr>'.$num.'</nobr></b></td></tr>';

// Increment the row count

$row_count++;

}

}

}

echo '</table>';

 

Link to comment
https://forums.phpfreaks.com/topic/103782-expanded-count-problem/
Share on other sites

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.