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
https://forums.phpfreaks.com/topic/130859-solved-array-pass-variables/
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);
}

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()

$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]

thanks for your post but...

 

I need to list the months in my array and also link them.

 

The results needed are the following:

<a href="Blog?x=' array of October 08's numbers '">October 08 (2)</a>

<a href="Blog?x=' array of February 07's numbers '">Febuary 07 (1)</a>

$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 
}
?>

Thats amazingly perfect thanks Samshel

 

I updated the last bit to make it more 'me' friendly lol

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

 

Archived

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

×
×
  • 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.