Jump to content


Photo

On This day in History… Array issues


  • Please log in to reply
4 replies to this topic

#1 Mouse

Mouse
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationToo Close to LONDON

Posted 14 October 2006 - 01:46 PM

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

<?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!';
?>


#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 14 October 2006 - 02:03 PM

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.

#3 Mouse

Mouse
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationToo Close to LONDON

Posted 14 October 2006 - 02:06 PM

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

#4 Mouse

Mouse
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationToo Close to LONDON

Posted 14 October 2006 - 02:32 PM

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

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

Mouse

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 October 2006 - 03:10 PM

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

<?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/>";
    }
}
?>

Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users