Jump to content

Recommended Posts

I have produced a noteboard style calendar where all events of a particular month are called and then number representing the date is shown and then the event after it. I'd like to know if possible the code which will order the numbers from the lowest to highest number.

 

<?php

function getevents($eventmonth){

$file = file("data.txt"); 

foreach($file as $key => $val){ 

  $data[$key] = explode("|", $val); 

  $day = $data[$key][0];
  $month = $data[$key][1];
  $event = $data[$key][2];

  if($month == $eventmonth){ 

   $out = "$day - $event<br>\n";
   print $out;

  }

}

}

getevents("Jan");
?>

Link to comment
https://forums.phpfreaks.com/topic/52575-putting-lists-in-order/
Share on other sites

So how would i successfully add this: (I know its not complete for each date)

 

<?php
$date = array("1st"=>"1st", "5th"=>"5th", "16th"=>"16th", "2nd"=>"2nd");
ksort($date);
foreach ($date as $key => $val) {
    echo "$key = $val\n";
}
?>

 

Into this:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<link href="rotary.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-color: #6191c2;
}
.style1 {color: #990000}
.style2 {
color: #990000;
font-weight: bold;
font-size: 10px;
font-family: verdana;
}
-->
</style></head>

<body>
<script language=JavaScript>
<!--



var message="Right click disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

// --> 
</script>

<p align="center" class="rotary"><u>Calendar of Events</u></p>
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left"><span class="rotary style1">January</span></div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
  

//Use the following function to retrive data for each month.
//Look at the data structure.

function getevents($eventmonth){

$file = file("data.txt"); //puts each line of the file into an array

foreach($file as $key => $val){ //loop through array

  $data[$key] = explode("|", $val); //breaks up each line into seperate arrays, values seperated by |

  $day = $data[$key][0];
  $month = $data[$key][1];
  $event = $data[$key][2];

  if($month == $eventmonth){ //will only list month you specify in function.

$dat = array("1"=>"1st", "5"=>"5th", "16"=>"16th", "2"=>"2nd");
ksort($dat);
foreach ($dat as $key => $val) {
    echo "$key = $val\n";
}

   $out = "$day - $event<br>\n";
   print $out;

  }

}

}

//Using the function
getevents("Jan");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">February</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Feb");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">March</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Mar");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">April</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Apr");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">May</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("May");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">June</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Jun");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">July</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Jul");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">August</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Aug");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">September</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Sep");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">October</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Oct");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">November</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Nov");
?>
    </span></div></td>
  </tr>
</table><br />
<table width="342" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="338"><div align="left" class="style2">December</div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="rotary">
      <?php
getevents("Dec");
?>
    </span></div></td>
  </tr>
</table>
</body>
</html>

 

The dates are stored as 1st, 2nd-->31st in the .txt file.

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.