Mouse Posted October 14, 2006 Share Posted October 14, 2006 On This day in History… Array issuesHello 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 wrongMany thanksMouse[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 laterecho $today;if ($today == $allqts) {echo '$quote', '<br /> On this day in $year' ;}elseecho ' - oooops no!';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23934-on-this-day-in-history%E2%80%A6-array-issues/ Share on other sites More sharing options...
hostfreak Posted October 14, 2006 Share Posted October 14, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/23934-on-this-day-in-history%E2%80%A6-array-issues/#findComment-108785 Share on other sites More sharing options...
Mouse Posted October 14, 2006 Author Share Posted October 14, 2006 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 helpsMouse Quote Link to comment https://forums.phpfreaks.com/topic/23934-on-this-day-in-history%E2%80%A6-array-issues/#findComment-108786 Share on other sites More sharing options...
Mouse Posted October 14, 2006 Author Share Posted October 14, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/23934-on-this-day-in-history%E2%80%A6-array-issues/#findComment-108792 Share on other sites More sharing options...
AndyB Posted October 14, 2006 Share Posted October 14, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/23934-on-this-day-in-history%E2%80%A6-array-issues/#findComment-108802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.