Jump to content

Recommended Posts

I have 2 columns group name, group members  in my database.  And  i would like to display the data this way

 

group name1                             

group member  // these are group members of group name 1 only

group member

group member

 

group name2

group members // these are group members of group name 2 only

group members

group members

 

do you know how this can be done? Please help

 

Link to comment
https://forums.phpfreaks.com/topic/46993-mysql-and-php-data-display/
Share on other sites

Hi ,

 

I have 2 columns in my database Food and  food types which i would like to display in the following format.

 

Fruits  // Food

oranges

tangerines  // Types of the food

 

Vegetables

cucumber

onions

 

I have the code below but the types just dont show up!

 

# ENTER NAME OF TABLE TO BE displayed

$groups = "SELECT  * FROM $dbtable ";

$grouped = mysql_db_query($db,$groups,$cid); //to obtain number of groups

$total_records = mysql_num_rows($grouped);

//$where = array();

echo "Rows:$total_records";

 

//$params=mysql_fetch_array($grouped)

 

while ($testparams=mysql_fetch_array($grouped)){

 

$tests = "SELECT * FROM $dbtable GROUP BY food ";

$tested = mysql_db_query($db,$tests,$cid);

$total_rec = mysql_num_rows($tested);

 

echo "<td valign=top>$testparams[food]</td>"; //to obtain the group names

echo "<br/>";

 

//for ( $counter=0; $counter<$totalRec; $counter ++) {

//while ($params=mysql_fetch_array($tested)){ //number of rows per group name

 

//$cow = "SELECT * FROM $dbtable WHERE group_id=".$testparams[food]." ORDER BY torder";

//$cows = mysql_db_query($db,$cow,$cid);

 

    //echo "cow";

echo $testparams['food_type'];

echo "<br/>";

//}

}

 

 

 

 

Please help fast!

 

 

 

try

<?php
# ENTER NAME OF TABLE TO BE displayed
$groups = "SELECT  * FROM $dbtable ORDER BY food";
$grouped = mysql_db_query($db,$groups,$cid); //to obtain number of groups
$total_records = mysql_num_rows($grouped);
//$where = array();
echo "Rows: $total_records";
echo '<table>';
//$params=mysql_fetch_array($grouped)
$prev_food = '';
while ($testparams=mysql_fetch_array($grouped)){   
$food=$testparams['food'];
$type = $testparams['food_type'];
if ($food != $prev_food) {
	echo "<td valign=top>$food</td>\n"; //to obtain the group names
	$prev_food = $food;
}
echo '<br />', $type, "\n";
}
?>

Craygo has already given you a perfectly sound solution to this problem in your other post of this problem, and from your reply, it looks as though you didn't even bother to try it. So stop double-posting and wasting our time.

Guest
This topic is now 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.