Jump to content

[SOLVED] Array pass variables


SeanHarding

Recommended Posts

I have an array of time() dates.

Im also grouping them by Month and by Year also displaying the number of times that month is repeated.

Here is my code:

$doomed = array();
$doomed[] = '1225294183';
$doomed[] = '1224689938';
$doomed[] = '1170862952';
foreach ($doomed as $k=>$v) {
$doom[]=date('F y',$v);
}

$result=array_count_values($doom);
foreach($result as $key=>$val) {
	echo '<a href="http://www.web_site/Blog/archive.php?x='. $key .'">'. $key .' ('. $val .')</a><br>';
	}

The result is a hyperlinked date year and amount of posts.

October 08 (2)
February 07 (1)

 

Is it possible for me to send the original timestamps for each month to another page via the URL?

 

e.g. http://www.website.co.uk/Blog/archive.php?x=' array of times '

 

Link to comment
Share on other sites

$doomed = array();
$doomed[] = '1225294183';
$doomed[] = '1224689938';
$doomed[] = '1170862952';
$serialz=serialize($doomed);
  $encode=urlencode($serialz);
  
   
?> <a href="http://www.web_site/Blog/archive.php?x=<?php echo $encode ?>">pass</a>

in archive.php

 

 

 


if($_GET)
{
$arr = unserialize(urldecode(stripslashes($_GET['x'])));
print_r($arr);
}

Link to comment
Share on other sites

Thanks again Zenag, but I only need October 08's variables in the array.

 

The bigger picture is... i'm selecting all the time() from my database and displaying them, i'm also grouping the time() by month and year....

 

Im linking these to another page so I can search my database and display results from only these time()

Link to comment
Share on other sites

$doomed = array();
$doomed[] = '1225294183';
$doomed[] = '1224689938';
$doomed[] = '1170862952';
$doom = array();
foreach ($doomed as $k=>$v) {
       if(date('Y') == date('Y', $v) && date('m') == date('m', $v)) {
$doom[]=date('F y',$v);
       }
}

$serialz=serialize($doom);
$encode=urlencode($serialz);
  
   
?> <a href="http://www.web_site/Blog/archive.php?x=<?php echo $encode ?>">pass</a>

 

this will send all time stamps from current month only..[Oct 2008]

Link to comment
Share on other sites

$doomed = array();
$doomed[] = '1225294183';
$doomed[] = '1224689938';
$doomed[] = '1170862952';
$doom = array();
foreach ($doomed as $k=>$v) {
   $doom[date('F y',$v)][] = $v;
}

foreach ($doom as $k=>$v) {
  $serialz=serialize($v);
  $encode=urlencode($serialz);
?>
<a href="http://www.web_site/Blog/archive.php?x=<?php echo $encode ?>"><?php echo $k ?></a>
<?php 
}
?>

 

 

Please note that the dates are passed encoded serialized...so on the page you are sending them they have to be decoded and unserialized, if you dont have control on that page, you can send the comma seperated like this

$doomed = array();
$doomed[] = '1225294183';
$doomed[] = '1224689938';
$doomed[] = '1170862952';
$doom = array();
foreach ($doomed as $k=>$v) {
   $doom[date('F y',$v)][] = $v;
}

foreach ($doom as $k=>$v) {
   $strDates = implode(",", $v);
?>
<a href="http://www.web_site/Blog/archive.php?x=<?php echo $strDates ?>"><?php echo $k ?></a>
<?php 
}
?>

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.