adam291086 Posted December 18, 2007 Share Posted December 18, 2007 This is how my array looks when printed Array ( [1] => Array ( [4] => Hit james ) ) Array ( [1] => Array ( [4] => Hit james ) [2] => Array ( [4] => Hit james [5] => Put james in hospital with a broken arm ) ) Array ( [1] => Array ( [4] => Hit james ) [2] => Array ( [4] => Hit james [5] => Put james in hospital with a broken arm ) [3] => Array ( [4] => Hit james [5] => Put james in hospital with a broken arm [10] => Put James in hospital with a dislocated knee ) ) This is how i created the array include 'config.php'; $result = mysql_query( " SELECT * FROM `table` WHERE `Month` = $thismonth AND `Year` = $thisyear") or die('Query failed. ' . mysql_error()); $arrDays = array(); $arrEvent = array(); while($row = mysql_fetch_array($result)) { $id = $row['ID']; $arrDays[] = $row['Day'] ; $Month = $row['Month'] ; $Year = $row['Year'] ; $arrEvent[$row['Day']] = $row['Event Details']; $arrBig[$row['ID']] = $arrEvent; print_r($arrBig); } This is the problem I want to echo the information for example when the day = 5. The reason the id is also in the array is because some days have multiple bits of information so the id makes the array unique. I can do this without the id in the way. But i am not confused? Any help is appreciated. I think i may of set the array up wrong Link to comment https://forums.phpfreaks.com/topic/82171-solved-array-help/ Share on other sites More sharing options...
rajivgonsalves Posted December 18, 2007 Share Posted December 18, 2007 I think you setup the array all wrong , its hard to tell what is what just looking at the array output... Link to comment https://forums.phpfreaks.com/topic/82171-solved-array-help/#findComment-417544 Share on other sites More sharing options...
adam291086 Posted December 18, 2007 Author Share Posted December 18, 2007 how do i set it up. I need an array to store the event id and the event day. This is for my calendar Link to comment https://forums.phpfreaks.com/topic/82171-solved-array-help/#findComment-417546 Share on other sites More sharing options...
adam291086 Posted December 18, 2007 Author Share Posted December 18, 2007 ok i have chaged the array to Array ( [4] => Hit james ) Array ( [4] => Hit james [5] => Put james in hospital with a broken arm ) Array ( [4] => Hit james [5] => Put james in hospital with a broken arm [10] => Put James in hospital with a dislocated knee ) while($row = mysql_fetch_array($result)) { $id = $row['ID']; $arrDays[] = $row['Day'] ; $Month = $row['Month'] ; $Year = $row['Year'] ; $arrEvent[$row['Day']] = $row['Event Details']; print_r($arrEvent); } This works fine. I need to make each entry unique so when there is two entries for the same day both are displayed. Link to comment https://forums.phpfreaks.com/topic/82171-solved-array-help/#findComment-417550 Share on other sites More sharing options...
rajivgonsalves Posted December 18, 2007 Share Posted December 18, 2007 your code should be include 'config.php'; $result = mysql_query( " SELECT * FROM `table` WHERE `Month` = $thismonth AND `Year` = $thisyear") or die('Query failed. ' . mysql_error()); $arrDays = array(); $arrEvent = array(); while($row = mysql_fetch_array($result)) { $id = $row['ID']; $arrDays[] = $row['Day'] ; $Month = $row['Month'] ; $Year = $row['Year'] ; $arrEvent[$row['Day']][] = $row['Event Details']; } then just use a implode on $arrEvent , if I remember correctly your code it should be implode("<BR>",$arrEvent[$i]); Link to comment https://forums.phpfreaks.com/topic/82171-solved-array-help/#findComment-417552 Share on other sites More sharing options...
adam291086 Posted December 18, 2007 Author Share Posted December 18, 2007 thank you so much. I now understand after some more reading on arrays Link to comment https://forums.phpfreaks.com/topic/82171-solved-array-help/#findComment-417556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.