Jump to content

On This day in History… Array issues


Mouse

Recommended Posts

On This day in History… Array issues

Hello all, can someone spot the mistake in here… cos I can’t!

I am aiming to get an on this day on history function on my site… (eventually to do a google type image change in the header…) but for now theres a bug here and my brain cant see where I am going wrong

Many thanks

Mouse

[code]
<?php

// Array Structure:  "Date","Quote","Year"

$allqts = array
    (
"1410", "tim created script...", "2006",
"1510", "tim posts script on site...", "2006",
"1610", "tim has minimal success...", "2006",
        );

// Gets the Total number of Items in the array then Divides by 3 because there is a date then a Quote followed by a year
$totalqts = (count($allqts)/3);

// Subtracted 1 from the total because '0' is not accounted for otherwise
$nmbr =($totalqts-1);
$nmbr = $nmbr*3;

// I think this is where it's going wrong...
$quote = $allqts[$nmbr];
        $nmbr = $nmbr+1;
$year = $allqts[$nmbr];
$nmbr = $nmbr+2;


$today = date(dm);

// check var is correct - remove later
echo $today;

if ($today == $allqts) {
echo '$quote', '<br /> On this day in $year' ;
}
else
echo ' - oooops no!';
?>
[/code]
Link to comment
Share on other sites

[code]
"1410", "tim created script...", "2006",
"1510", "tim posts script on site...", "2006",
"1610", "tim has minimal success...", "2006", [color=red]<--[/color]
[/code]

thought it might be the last comma, the code would have been searching another value... but no....!

Mouse
Link to comment
Share on other sites

Not sure if this helps you, but I'd have approached it slightly differently (example below works):

[code]<?php

// Array Structure:  "Date|Quote|Year"

$allqts = array
    (
"1410|tim created script...|2006",
"1510|tim posts script on site...|2006",
"1610|tim has minimal success...|2006",
"1410|Andy edited it|2006"
        );

$today = date(dm);
for ($i=0;$i<count($allqts);$i++) {
    $bits = explode("|",$allqts[$i]);
    if ($bits[0] == $today) {
        echo $bits[1]. "<br/>On this day is ". $bits[2]. "<br/>";
    }
}
?>[/code]
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.