mickinell Posted May 30, 2008 Share Posted May 30, 2008 I'm sure there's a simple solution to this, but I don't know enough about what I'm doing to figure it out. I have this code: $currmapquery = "SELECT * FROM lesson_plan LEFT JOIN plan_items ON FIND_IN_SET(plan_items.item_id, lesson_plan.item_id) WHERE plan_items.item_type = 'STA1'"; $currmap = @mysql_query($currmapquery, $connection) or die(mysql_error()); while($row = mysql_fetch_array($currmap)) { $plan_id = $row['plan_id']; $item_id = $row['item_id']; $item_name = $row['item_name']; $item_desc = $row['item_desc']; $date = $row['date']; $display_block .= "<tr><td>$item_name, $item_desc</td><td><a href=\"displayplan.php?plan_id=$plan_id\">$date</a></td></tr>"; } And that does give me the data I want...but not the way I want it. The field item_id is an array in lesson_plan that refers to the item_id stored in plan_items. What I want to display is a table that has rows like this: ITEM INFO || Plan 1, Plan 2, Plan 3 What I'm getting now is ITEM 1 || Plan 1 ITEM 1 || Plan 2 ITEM 1 || Plan 3 Can someone point me in the right direction? Link to comment https://forums.phpfreaks.com/topic/108054-solved-displaying-data-from-an-array/ Share on other sites More sharing options...
GingerRobot Posted May 30, 2008 Share Posted May 30, 2008 Sounds like what you need to do is order by the item_id then keep track of the item_id and check it each time the loop is run. If it's the same as last time, dont show the item info. Something like: $currmapquery = "SELECT * FROM lesson_plan LEFT JOIN plan_items ON FIND_IN_SET(plan_items.item_id, lesson_plan.item_id) WHERE plan_items.item_type = 'STA1' ORDER BY item_id"; $currmap = @mysql_query($currmapquery, $connection) or die(mysql_error()); $prev_item = ''; while($row = mysql_fetch_assoc($currmap)) { $plan_id = $row['plan_id']; $item_id = $row['item_id']; $item_name = $row['item_name']; $item_desc = $row['item_desc']; $date = $row['date']; if($prev_item != $item_id){ echo "<br />\n".$item_name.' || '; }else{ echo ', '; } $prev_item = $item_id; echo $plan_id; } Link to comment https://forums.phpfreaks.com/topic/108054-solved-displaying-data-from-an-array/#findComment-553879 Share on other sites More sharing options...
mickinell Posted May 30, 2008 Author Share Posted May 30, 2008 Thanks! I tried that and with a little modifcation (had to add the table name to the order by), it worked! Link to comment https://forums.phpfreaks.com/topic/108054-solved-displaying-data-from-an-array/#findComment-553883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.