rwtrwt2003 Posted April 2, 2009 Share Posted April 2, 2009 I need help in makeing a table with the data that I have in my sql database. Here is a example of what is in my database. ID Switch Start_Date Year Month Day Completed_by Comments 1 Test1 090309 2009 03 10 test test 2 Test4 090309 2009 03 10 test test2 3 Test2 090309 2009 03 10 test1 test3 in my sql query i am select * from table where year = year and completed_by = completed_by What i get know is this Completed_By#SwitchesSwitches test0Test4 test10Test2 What I want is this Completed_By#SwitchesSwitches test2Test4,Test1 test11Test2 Below is the Php code that I am useing <?php do { ?> <?php $myhash[$row_getPerson['Completed_By']] = $row_getPerson['Switch']; ?> <?php } while ($row_getPerson = mysql_fetch_assoc($getPerson)); ?> <?php $count = 0; arsort ($myhash); foreach ($myhash as $key => $value) { $count++; ?> <tr> <td nowrap="nowrap"><?php echo $key; ?></td> <td nowrap="nowrap"><?php echo $count;?></td> <td nowrap="nowrap"><?php echo $value; ?></td> </tr> <?php } ?> Any Help would Link to comment https://forums.phpfreaks.com/topic/152242-solved-need-help-in-printing-array/ Share on other sites More sharing options...
sasa Posted April 2, 2009 Share Posted April 2, 2009 <?php do { $myhash[$row_getPerson['Completed_By']][] = $row_getPerson['Switch']; } while ($row_getPerson = mysql_fetch_assoc($getPerson)); arsort ($myhash); foreach ($myhash as $key => $value){ $count = count($value); $value = implode(', ', $value); echo " <tr> <td nowrap=\"nowrap\">$key</td> <td nowrap=\"nowrap\">$count</td> <td nowrap=\"nowrap\">$value;</td> </tr>"; } Link to comment https://forums.phpfreaks.com/topic/152242-solved-need-help-in-printing-array/#findComment-799540 Share on other sites More sharing options...
rwtrwt2003 Posted April 2, 2009 Author Share Posted April 2, 2009 I made the changes. Here is what I did <?php do { ?> <?php $myhash[$row_getPerson['Completed_By']][] = $row_getPerson['Switch']; ?> <?php } while ($row_getPerson = mysql_fetch_assoc($getPerson)); ?> <?php arsort ($myhash); foreach ($myhash as $key => $value) { $count = count($value); $value = implode(', ', $value); echo " <tr> <td nowrap=\"nowrap\"><$key</td> <td nowrap=\"nowrap\"><$count</td> <td nowrap=\"nowrap\"><$value</td> </tr>";?> <?php } ?> but it doesnt work. This is what I get Completed_By #Switches Switches <2 <1 Link to comment https://forums.phpfreaks.com/topic/152242-solved-need-help-in-printing-array/#findComment-799584 Share on other sites More sharing options...
rwtrwt2003 Posted April 2, 2009 Author Share Posted April 2, 2009 It works thank you. I took my code out and replaced it with yours and it worked. Thank you Link to comment https://forums.phpfreaks.com/topic/152242-solved-need-help-in-printing-array/#findComment-799600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.