Jump to content

Array Question


adam291086

Recommended Posts

You can do something like this:

<?php
$adam= array();
while($row = mysql_fetch_array($result))
{
  if (isset($adam[$row['Day']])) {
     $tmp = explode('~',$adam[$row['Day']]);
     $tmp[] = $row['Event Details'];
     $adam[$row['Day']] = implode('~',$tmp); }
  else
     $adam[$row['Day']] = $row['Event Details'];
}
?>

 

For this to work, you have to pick a character that is not used in the $row['Event Details'] string to be the delimiter.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/80623-array-question/#findComment-408911
Share on other sites

ok, thanks ken i get the idea. Therefore i have added ID to the database for each event. Therefore i have made each event individual. But when i echo the array i just get [0] can anyone see why

 

This is where i set up the array

 

$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['ID']]  = $row['Event Details']; 

 

This is when i echo the array

(in_array($counter,$arrDays))
{

for ($i=$counter;$i<=$counter;$i++)
{  
for ($a=0;$a<=$ID;$a++)
{
echo "<td><a href=#>$counter<span>$arrEvent[$i][$a]</span></td></a>";
}
}
}

else
{
echo "<td>$counter</td>"; 
}

Link to comment
https://forums.phpfreaks.com/topic/80623-array-question/#findComment-408926
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.