Jump to content

[SOLVED] php events box


chwebdesigns

Recommended Posts

Hi, Is there a way to get the PHP code to read a line from the table and write it in a box? What I have is an events table with two columns, Date of Event & Name of Event. This is saved on a page called events.html (can be changed to .php) What I wan is on index.php I want a next event box. So what I want for it is to read from the events page, and find when the next event is, using information on dates. I have no idea on how to start this at all.

If you require any other information then just ask

From Cal

 

PS ~ I'm a novice at PHP

Link to comment
https://forums.phpfreaks.com/topic/54161-solved-php-events-box/
Share on other sites

<?php

function textbetweenarray($s1,$s2,$s){
  $myarray=array();
  $s1=strtolower($s1);
  $s2=strtolower($s2);
  $L1=strlen($s1);
  $L2=strlen($s2);
  $scheck=strtolower($s);

  do{
  $pos1 = strpos($scheck,$s1);
  if($pos1!==false){
$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
if($pos2!==false){
  $myarray[]=substr($s,$pos1+$L1,$pos2);
  $s=substr($s,$pos1+$L1+$pos2+$L2);
  $scheck=strtolower($s);
  }
	}
  } while (($pos1!==false)and($pos2!==false));
return $myarray;
}

$content = file_get_contents("events.html");

$table = textbetweenarray("<table>", "</table>", $content);
$table = $table[0];

$tds = textbetweenarray("<td>", "</td>", $table);
$date = $tds[0];
$name = $tds[1];

echo "Next event: {$name} on {$date}!";

?>

Link to comment
https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267758
Share on other sites

That works for the Event but it doesn't work for the date. Here is the code for my table:

<table width="567" border="1" align="center" cellpadding="0" cellspacing="0" id="events">
                <tr bgcolor="#FF9933">
                  <td colspan="2"><div align="center">
                    <p><strong>JUNE</strong></p>
                    </div></td>
                  </tr>
                <tr>
                  <td width="120"><div align="center">
                    <p>Sun 3rd June </p>
                  </div></td>
                  <td width="441"><div align="center">
                    <p>Int. Comp</p>
                  </div></td>
                </tr>
                <tr>
                  <td width="120"><div align="center">
                    <p>Sat 9th June </p>
                  </div></td>
                  <td><div align="center">
                    <p>Class 3 Judges Course</p>
                  </div></td>
                </tr>
                <tr>
                  <td width="120"><div align="center">
                    <p>Sun 10th June </p>
                  </div></td>
                  <td><div align="center">
                    <p>Comp</p>
                  </div></td>
                </tr>
                <tr>
                  <td width="120"><div align="center">
                    <p>Sun 24th June </p>
                  </div></td>
                  <td><div align="center">
                    <p>First Aid Course</p>
                  </div></td>
                </tr>
                <tr bgcolor="#FF9933">
                  <td colspan="2"><div align="center">
                    <p><strong>JULY</strong></p>
                  </div></td>
                  </tr>
                <tr>
                  <td width="120"><div align="center">
                    <p>Sun 1st July 07 </p>
                  </div></td>
                  <td><div align="center">
                    <p>Comp </p>
                  </div></td>
                </tr>
                <tr>
                  <td width="120"><div align="center">
                    <p>Sat 7th & <br>
                      Sun 8th July </p>
                  </div></td>
                  <td><div align="center">
                    <p>Seminar 321</p>
                  </div></td>
                </tr>
                <tr>
                  <td width="120"><div align="center">
                    <p>Sun 15th July </p>
                  </div></td>
                  <td><div align="center">
                    <p>Grading 8 </p>
                  </div></td>
                </tr>
                <tr>
                  <td width="120"><div align="center">
                    <p>Sun 22nd July </p>
                  </div></td>
                  <td><div align="center">
                    <p>Competition 198</p>
                  </div></td>
                </tr>
                       </table>

 

Thanks for your help from cal

Link to comment
https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267771
Share on other sites

<?php

function textbetweenarray($s1,$s2,$s){
  $myarray=array();
  $s1=strtolower($s1);
  $s2=strtolower($s2);
  $L1=strlen($s1);
  $L2=strlen($s2);
  $scheck=strtolower($s);

  do{
  $pos1 = strpos($scheck,$s1);
  if($pos1!==false){
$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
if($pos2!==false){
  $myarray[]=substr($s,$pos1+$L1,$pos2);
  $s=substr($s,$pos1+$L1+$pos2+$L2);
  $scheck=strtolower($s);
  }
	}
  } while (($pos1!==false)and($pos2!==false));
return $myarray;
}

$content = file_get_contents("events.html");

$table = textbetweenarray("<table width=\"567\" border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" id=\"events\">", "</table>", $content);
$table = $table[0];

$tr = textbetweenarray("<tr>", "</tr>", $table);
$tr = $tr[0];

$data = textbetweenarray("<p>", "</p>", $tr);
$name = $data[0];
$date = $data[1];

echo "Next event: {$name} on {$date}!";

?>

 

Try that?

Link to comment
https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267773
Share on other sites

Yes thank you, the date and competition info work fine now. Is there a way of getting it to update automatically to the date? For e.g. : The top event on the calendar at the moment is Sun 3rd June, which was yesterday, could it automatically show the next event?

Thanks very much

from

cal

Link to comment
https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267777
Share on other sites

You can try this.. :

 

<?php

function textbetweenarray($s1,$s2,$s){
  $myarray=array();
  $s1=strtolower($s1);
  $s2=strtolower($s2);
  $L1=strlen($s1);
  $L2=strlen($s2);
  $scheck=strtolower($s);

  do{
  $pos1 = strpos($scheck,$s1);
  if($pos1!==false){
$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
if($pos2!==false){
  $myarray[]=substr($s,$pos1+$L1,$pos2);
  $s=substr($s,$pos1+$L1+$pos2+$L2);
  $scheck=strtolower($s);
  }
	}
  } while (($pos1!==false)and($pos2!==false));
return $myarray;
}

$content = file_get_contents("events.html");

$table = textbetweenarray("<table width=\"567\" border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" id=\"events\">", "</table>", $content);
$table = $table[0];

$tr = textbetweenarray("<tr>", "</tr>", $table);
$tr = $tr[0];

$data = textbetweenarray("<p>", "</p>", $tr);
$name = $data[0];
$date = $data[1];

$timestamp = strtotime($date);
$output = date("D/M/Y", $timestamp);

echo "Next event: {$name} on {$output}!";

?>

 

Not sure if that'll work though..

Link to comment
https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267809
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.