Rony Posted July 10, 2006 Share Posted July 10, 2006 I am getting values from a sql query and storing them in an array using the array_push function. I have tried many many things to print the array $conatiner or rather pass the values of the array into the URL. It only seems to work if you use the print_r command. I even tried using that but it would add a lot of other data which is not necessary. I have been trying to figure this out for 2 weeks now !! ??? Please help !!<?php include connection file;$result = mysql_query(" my query") or die ("LSE usage query failed");$container = array(); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $diff = $row{'end_ts'} - $row{'start_ts'} ; $value= gmdate( 'H:i:s ', $diff ); array_push($container, array($value)) ; }$url="http://...//piechart.php?d[]=". [color=red]$container[/color] . "&l[]=time&t=Test";?><a href="<?php echo $url; ?>">click me</a> Quote Link to comment https://forums.phpfreaks.com/topic/14207-problems-appending-to-a-url-array-values/ Share on other sites More sharing options...
willfitch Posted July 10, 2006 Share Posted July 10, 2006 Hey Rony,It appears you may be going at this a little too weird. You are actually putting the array values inside the URL? Why don't you build a comma seperated list, and assign them to a get variable? Can you please explain what the recieving file looks like as well? Quote Link to comment https://forums.phpfreaks.com/topic/14207-problems-appending-to-a-url-array-values/#findComment-55715 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2006 Share Posted July 10, 2006 If you want to pass an array via a URL, you have to serialize it first.[code]<?php $url="http://...//piechart.php?d[]=". serialize($container) . "&l[]=time&t=Test"; ?>[/code]In the processing script you need to unserialize to get the array back into a usable form:[code]<?php $url = unserialize($_GET['d'][0]); ?>[/code]One question ... why are you using an array specification "d[]" in the URL?Ken Quote Link to comment https://forums.phpfreaks.com/topic/14207-problems-appending-to-a-url-array-values/#findComment-55719 Share on other sites More sharing options...
Rony Posted July 10, 2006 Author Share Posted July 10, 2006 I am passing the values to the URL to create a pie chart. Example if the array has values $conatiner = {3,7};The url should actually be http://...../piechart.php?d[]=[color=red]3[/color]&l[]=windows&d[]=[color=red]7[/color]&l[]=apple&t=TestThis would show me the piechart.I get there values 3, 7 etc from the database. I thought storing them in an array and then passing them would do teh trick. I know I need a loop for it and I tried foreach but that didnt work. How can I build a comma seperated list? Quote Link to comment https://forums.phpfreaks.com/topic/14207-problems-appending-to-a-url-array-values/#findComment-55720 Share on other sites More sharing options...
ShogunWarrior Posted July 10, 2006 Share Posted July 10, 2006 First what you need is what way the script on the other end is picking it up.You could think about using [b]serialize[/b] and [b]urlencode[/b] to send the whole array and then [b]urldecode[/b] and [b]unserialize[/b] to turn it back into an array.Alternatively you could send them like ?v1=x&v2=x&v3=x etc. and then cycle through all the URL parameters with V in the start.It all depends on what way you are interpreting it. Quote Link to comment https://forums.phpfreaks.com/topic/14207-problems-appending-to-a-url-array-values/#findComment-55721 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2006 Share Posted July 10, 2006 You can create a comma seperated list from an array by using the implode() function:[code]<?php $csl = implode(',',$arr); ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/14207-problems-appending-to-a-url-array-values/#findComment-55722 Share on other sites More sharing options...
Rony Posted July 10, 2006 Author Share Posted July 10, 2006 Ken, I tried the implode function before. It just gives me Array,Array,Array How do I get the actual values (I also tried array_values)Shogun, I didnt not understand how can I passteh variables like ?v1=x&v2=x&v3=x I trying the serialize and urlencode now Quote Link to comment https://forums.phpfreaks.com/topic/14207-problems-appending-to-a-url-array-values/#findComment-55727 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2006 Share Posted July 10, 2006 You're getting that because of this statement:[code]<?php array_push($container, array($value)); ?>[/code]This is creating a 2-level array. If you do a [code]<?php echo '<pre>' . print_r($container,true) . '</pre>'; ?>[/code] you will see that each entry is an array. This also explains why you've been having problems with the foreach statement.Change that line to be [code]<?php $container[] = $value; ?>[/code] which will create a plain array.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14207-problems-appending-to-a-url-array-values/#findComment-55746 Share on other sites More sharing options...
Rony Posted July 10, 2006 Author Share Posted July 10, 2006 Ken, It worked !! I had used simple array before I looked up array_push but I dont know what I did differently then. Before it kept on showing me just the last value in the array outside the while loop. Everyone thank you for all your help !! :D Quote Link to comment https://forums.phpfreaks.com/topic/14207-problems-appending-to-a-url-array-values/#findComment-55776 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.