Jump to content

Events with several start-datefields


tempi

Recommended Posts

Hi there,

 

I'm working with php in combination with mysql and couldn't figure out how to solve the following problem/task:

 

I have an event-table with fields like: Title, Location, Time, Name, Startdate1, Startdate2, Startdate3

 

So the thing is, that I like to print out one event for all the different startdates.

 

Let's say one eventrecord looks like ('Fishing','Lake Bana', '14:00', 'Michael Scofield', '2007-08-12', '2007-08-27', '2007-09-03'

 

Then the output should be like

 

'Fishing','Lake Bana', '14:00', 'Michael Scofield', '2007-08-12'

'Fishing','Lake Bana', '14:00', 'Michael Scofield', '2007-08-27'

'Fishing','Lake Bana', '14:00', 'Michael Scofield', '2007-09-03'

 

The problem is, that each event has these different startdates and in the end, all the events shoul be sorted by the date. So startdate3 from record1 could come after startdate1 from record2. Can I get these chronologically right?

 

I hope you understand what I mean.

 

Is this solvable?

 

Thanks for any help!

Tempi

Link to comment
Share on other sites

  // this function sort double array by given key name
  function SortArrayByValue($ar, $keyname, $desc = false) {
    if (!is_array($ar) || empty($keyname)) return $ar;
    $arsort = array();
    reset($ar);
    while(list($key, $rad) = each($ar)) {
      $val = $rad[$keyname];
      $v   = 1;
      while(isset($arsort[$val])) $val = $rad[$keyname].' '.$v++;
      $arsort[$val] = $key;
    }
    if ($desc) krsort($arsort);
    else ksort($arsort);

    reset($arsort);
    
    $retar = array();
    while(list(,$key) = each($arsort))
      $retar[$key] = $ar[$key];
    
    return $retar;
  }

  $arevents = array();
  while($row = mysql_fetch_array($result)) {
    $startdays = array($row['Startdate1'], $row['Startdate2'], $row['Startdate3']);
    if (!empty($startdays[0])) {
      $row['Startdate'] = $startdays[0];
      $row['Sortway'] = $row['Startdate'].' '.$row['Time'];
      $arevents[] = $row;
    }
    if (!empty($startdays[1])) {
      $row['Startdate'] = $startdays[1];
      $row['Sortway'] = $row['Startdate'].' '.$row['Time'];
      $arevents[] = $row;
    }
    if (!empty($startdays[2])) {
      $row['Startdate'] = $startdays[2];
      $row['Sortway'] = $row['Startdate'].' '.$row['Time'];
      $arevents[] = $row;
    }
  }
  if (count($arevents) > 0) 
    $arevents = SortArrayByValue($arevents, 'Sortway', false);

  //listevents
  reset($arevents);
  while(list(,$row) = each($arevents)) 
     echo $row['Startdate'].' '.$row['Title'].'<br />';

 

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.