maliary Posted April 14, 2007 Share Posted April 14, 2007 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 More sharing options...
MadTechie Posted April 14, 2007 Share Posted April 14, 2007 yes.. GROUP BY group and echo a new "title" when the group changes, other than that its just a loop, if you showed some php code, we could help more.. or maybe the freelance section Link to comment https://forums.phpfreaks.com/topic/46993-mysql-and-php-data-display/#findComment-229170 Share on other sites More sharing options...
maliary Posted April 15, 2007 Author Share Posted April 15, 2007 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! Link to comment https://forums.phpfreaks.com/topic/46993-mysql-and-php-data-display/#findComment-229596 Share on other sites More sharing options...
sasa Posted April 15, 2007 Share Posted April 15, 2007 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/46993-mysql-and-php-data-display/#findComment-229601 Share on other sites More sharing options...
Barand Posted April 15, 2007 Share Posted April 15, 2007 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. Link to comment https://forums.phpfreaks.com/topic/46993-mysql-and-php-data-display/#findComment-229604 Share on other sites More sharing options...
Recommended Posts