Jump to content

Archived

This topic is now archived and is closed to further replies.

Mouse

On This day in History… Array issues

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]

Share this post


Link to post
Share on other sites
It would help us if you posted any errors you are getting, if any at all. And/Or post what is not working.

EDIT:
Sorry, didn't see you posted your problems in the code as comments. Will look it over and see if I can give you an answer.

Share this post


Link to post
Share on other sites
Quite right... sorry.

i am not getting any errors... but in stead of the "tim created this script on this day in 2006" i was expecting i am getting the oooops message.

hope that helps


Mouse

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.