Jump to content

Look to change the information in array B when array A has a specific value


gazza3665

Recommended Posts

Hello

 

Can some offer me some help; I have minimal knowledge of PHP, the original script I have was written for me, I have made some minor updates but don't really have a full understanding of how it works.

 

A good example of what I currently have can be found at http://www.stroudskittles.co.uk/team.php?div=A&team=PatchRatsA

 

The script Highlights the date for the Cup game in Blue and the Bank holiday in Red; what I'm looking to achieve is modify the Opponents value so that after the team name it states "Cup Game" or Bank Holiday"

 

The Script reads a csv file, when the value for $tdate equals $bankHols or $cup the colour is changed; however I want to change $tverses as well

 

The script I have is as follows; any assistance would be appreciated

 

Many Thanks

<?php
$div = $_GET["div"];
$team = $_GET["team"];
$localTime=time();
$localTime=$localTime - (60 * 60 * 1);
$thisDay = date("d",$localTime);
$thisMonth = date("m",$localTime);
$thisYear = date("Y",$localTime);
$bankHols = '[25 Mar 16][28 Mar 16][14 Apr 17][17 Apr 17][30 Mar 18][2 Apr 18][19 Apr 19][22 Apr 19][10 Apr 20][13 Apr 20]';
$cupdate = '[12 Sep 16][13 Sep 16][14 Sep 16][15 Sep 16][16 Sep 16]';
$embold='N';
if (strlen($div) == 1){
$divCsv = 'csv/dSection'.$div.'.csv';
$SectionName = 'Section '.$div;
}
else {
$divCsv = 'csv/dLadiesSection'.substr($div,1,1).'.csv';
$SectionName = 'Ladies Section '.substr($div,1,1);
}
$fCnt=0;
// process list file
$fd = fopen ("$divCsv", "r");
// initialize a loop to go through each line of the file
while (!feof ($fd)) {
// declare an array to hold all of the contents of each row, indexed
$buffer = fgetcsv($fd, 4096);
// the 10 represents the number of columns in the text file
for ($i = 0; $i < 10; ++$i){
if ($i == 0){
$id = $buffer[$i];
}
if ($i == 1){
$name = $buffer[$i];
}
if ($i == 2){
$alley = $buffer[$i];
}
if ($i == 3){
$day = $buffer[$i];
}
if ($i == 4){
$captain = $buffer[$i];
}
if ($i == 5){
$vice = $buffer[$i];
}
if ($i == 6){
$phone = $buffer[$i];
}

if ($i == 7){
$vicephone = $buffer[$i];
}
if ($i == {
$tcsv = $buffer[$i];
}
if ($i == 9){
$www = $buffer[$i];
}
}
if ($team == $tcsv){
$nameH = $name;
$alleyH = $alley;
$dayH = $day;
$captainH = $captain;
$viceH = $vice;
$phoneH = $phone;
$vicephoneH = $vicephone;
$wwwH = $www;
}
}
$pageTitle = $nameH ;
include ('pageheader.php');


echo "<p align=\"left\"><span class=\"title\">$nameH League Fixtures</span></p>";
?>

<center>

<b><script language="JavaScript1.2" src="javascript/fixtures.js"></script></b>

<?php include ('amendment'.$div.'.php'); ?>


<script language="JavaScript1.2" src="javascript/amendment.js"></script>
<br>

</center>

<?php
echo "<table width=\"755\" align=\"center\">\n";
echo "<tr>\n";
echo "<td valign=\"TOP\" width=\"755\" align=\"center\">\n";
echo "<table class=\"BORDER\">\n";
fclose ($fd);
$mmOld='';
$csvFile = 'csv/t'.$team.'.csv';
// process division file
$fd = fopen ("$csvFile", "r");
// initialize a loop to go through each line of the file
while (!feof ($fd)) {
// declare an array to hold all of the contents of each row, indexed
$buffer = fgetcsv($fd, 4096);
// the 6 represents the number of columns in the text file
for ($i = 0; $i < 6; ++$i){
if ($i == 0){

$tweek = $buffer[$i];
}
if ($i == 1){
$tdate = $buffer[$i];
if (strpos($bankHols, '['.$tdate.']') !== false) {
$tdate = strtoupper($tdate);
$tdate = "<span style=\"color:red\"><b><i>$tdate</i></b></span>";

}
else if ($i == 1){
$tdate = $buffer[$i];
if (strpos($cupdate, '['.$tdate.']') !== false) {
$tdate = strtoupper($tdate);
$tdate = "<span style=\"color:blue\"><b><i>$tdate</i></b></span>";
}
}

list($fDay, $fMonth, $fYear) = split(" ", $tdate);
$chkMonth = $fMonth;
$date_formatted = "$fDay $fMonth $fYear";
$final_date = strtotime($date_formatted);
$fDay = date("d",$final_date);
$fMonth = date("m",$final_date);
$fYear = date("Y",$final_date);
if ($fYear == $thisYear & $fMonth == $thisMonth & $fDay == $thisDay & $embold=='N'){
$embold = 'Y';
}

elseif ($fYear == $thisYear & $fMonth == $thisMonth & $fDay >= $thisDay & $embold=='N'){
$embold = 'Y';
}
elseif ($fYear >= $thisYear & $fMonth > $thisMonth & $embold=='N'){
$embold = 'Y';
}
elseif ($fYear > $thisYear & $embold=='N'){
$embold = 'Y';
}
}
if ($i == 2){
$tday = $buffer[$i];
}
if ($i == 3){
$tversus = $buffer[$i];
}
if ($i == 4){
$thora = $buffer[$i];
}
if ($i == 5){
$talley = $buffer[$i];
}
}
++$fCnt;
if ($fCnt == 1){
echo "<tr>\n";
echo "<td NOWRAP class=\"HDR\" colspan=\"6\"><b>$nameH</b></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td NOWRAP class=\"NORMAL\" colspan=\"6\">\n";
echo "<b>$SectionName</b>\n";
echo "<br>Captain: <b>$captainH</b> Tel: <b>$phoneH</b>\n";
{
echo "<br><i>Vice Captain: <b>$viceH</b> Tel: <b>$vicephoneH</b></i>\n";
}
$alleyAbbrev = preg_replace("/[^a-zA-Z0-9]/", "", $alleyH);
echo "<br>Home: <b>$alleyH</b> Home Night: <b>$dayH</b>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td NOWRAP class=\"TITLE\" width=\"50\" align=\"center\"><b>Week</b></td>\n";
echo "<td NOWRAP class=\"TITLE\" width=\"90\" align=\"center\"><b>Date</b></td>\n";
echo "<td NOWRAP class=\"TITLE\" width=\"90\" align=\"center\"><b>Day</b></td>\n";
echo "<td NOWRAP class=\"TITLE\" width=\"225\" align=\"center\"><b>Versus</b></td>\n";
echo "<td NOWRAP class=\"TITLE\" width=\"75\" align=\"center\"><b>H/A</b></td>\n";
echo "<td NOWRAP class=\"TITLE\" width=\"225\" align=\"left\"><b>Alley</b></td>\n";
echo "</tr>\n";
}
if ($chkMonth == 'Jan' and $mmOld == 'Dec'){
echo "<tr>\n";
echo "<td NOWRAP colspan=\"6\" class=\"TITLECENTER\"><img src=\"image/blank.gif\"></td>\n";
echo "</tr>\n";
}
if ($tweek != '' & $embold != 'Y'){
echo "<tr>\n";
echo "<td NOWRAP class=\"NORMALCENTER\" width=\"50\" align=\"center\">$tweek</td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"90\" align=\"center\">$tdate</td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"90\" align=\"center\">$tday</td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"225\" align=\"center\">$tversus</td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"75\" align=\"center\">$thora</td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"225\" align=\"left\">$talley</td>\n";
echo "</tr>\n";
}
if ($tweek != '' & $embold == 'Y'){
echo "<tr>\n";
echo "<td NOWRAP class=\"NORMALCENTER\" width=\"50\" align=\"center\"><b>$tweek</b></td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"90\" align=\"center\"><b>$tdate</b></td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"90\" align=\"center\"><b>$tday</b></td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"225\" align=\"center\"><b>$tversus</b></td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"75\" align=\"center\"><b>$thora</b></td>\n";
echo "<td NOWRAP class=\"NORMAL\" width=\"225\" align=\"left\"><b>$talley</b></td>\n";
$embold='X';
echo "</tr>\n";
}
$mmOld = $chkMonth;
}
fclose ($fd);
Link to comment
Share on other sites

Did you pay someone to write this for? Because if you did, you got ripped off. The person who wrote this knows only slightly more about PHP than you do. This code is a mish-mash of html, php, js all tumbled together and making no sense to a newcomer trying to help you.

 

Here's the first thing that was written stupidly. You took the dates for your holidays and built a string with brackets in it. Why? To do searches for specific values? Why not build an array and simply use a proper array function to find a date value in the array? If you are going to do a search of a string, why the brackets? It looks to me like someone THOUGHT they were creating an array, but alas, they were not using the correct syntax.

 

I tried to follow some of the rest of this but gave up. Really this is (in the most gentle term I can think of) crap. Give it back to whoever wrote it and tell him/her to do a better job, or better yet, both of you sit down and take a PHP course together.

Link to comment
Share on other sites

The script was written by someone who learnt php so no I didn't pay for it. Much of the javascript was added by myself as I have a better understanding of this.

 

The script actually works well - the only issues I have is if I have an error in the csv file

 

From what you are saying I need to learn php before I can do anything; it's not something that I can easily modify - if this is the case can you point me in the direction of a good book to learn PHP or provide some advice on updating the script

 

Thanks

Link to comment
Share on other sites

Well, he didn't "learnt" it very well. In fact I'll bet he is still "learnt-ing" it.

 

As for updating the script - I wouldn't waste my time. Learn and re-write. As for course/sites - there are a few but since I have never used any of them, I'll let the rest of the forum refer you to their faves.

 

Here's a tip that will eliminate about 50 lines of code from this debacle:

 

http://php.net/manual/en/function.list.php

 

The list function is a great tool.

 

 

Also - keep this url bookmarked so that you can reference the php manually readily. You're going to need it:

 

http://www.php.net/manual/en/funcref.php

Link to comment
Share on other sites

Well, he didn't "learnt" it very well. In fact I'll bet he is still "learnt-ing" it.

 

Why the quotes around the word "learnt"? It is a valid past tense of the verb "learn" - however, the version "learned" is more common, especially in the US.

 

 

@gazza3665: can you provide an example csv file that is used by the above script?

Edited by Psycho
Link to comment
Share on other sites

Well, I'll be.

 

Now from my experience - if I ever hear or see that word used it tells me (and has told me) that I'm dealing with someone who doesn't speak or write very good English. In fact I think my English teachers would be shocked if I ever used it. Now from what you say I have to change 50+ years of behavior.

Edited by ginerjm
Link to comment
Share on other sites

Well, I'll be.

 

Now from my experience - if I ever hear or see that word used it tells me (and has told me) that I'm dealing with someone who doesn't speak or write very good English. In fact I think my English teachers would be shocked if I ever used it. Now from what you say I have to change 50+ years of behavior.

 

Well, you are obviously not using the Queen's English!

Link to comment
Share on other sites

Now from my experience - if I ever hear or see that word used it tells me (and has told me) that I'm dealing with someone who doesn't speak or write very good English.

 

i was the same way. I recall a story some years back where some celebrity used it during an awards show and was lambasted over the internet whereby it was reported that it is, in fact, a real word. I always considered it similar to the non-word "ain't".

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.