Jump to content

[SOLVED] Array Help


adam291086

Recommended Posts

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

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

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

Archived

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