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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.