only return 1 value array();

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

only return 1 value array();

Post by ianhull »

Hi Guys,

can anyone please tell me why this is happening?

It is only returning the last values.

Code: Select all


<?php

foreach ( $_GET as $varName => $postData ) 

$columnName = array("{$varName}",);
$dataValue = array("{$postData}",);

print_r(array_combine($columnName,$dataValue));

?>


User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

several things
  • $columnName is the only line in the loop.
  • your code is creating a new array each time $columnName is set, wiping out all previous information.
  • I don't see the point of this code. It appears you're simply copying $_GET.
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Thanks Feyd,

In the end I will be collecting data from a POST form and entering the data into my DB,

First of all what I'm tring to do here is retrieve all the posted data as value pairs and place them into an array for later insertion into my db.

I know that this is not very secure, but for now it is ok.

How would I get it to loop through all the posted data and place all entries into an array?

thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

array_keys() and array_values() may be of interest.
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Thanks Feyd, Managed to get that working fine now :)

One other thing,

Do you know how to get the referer domain only, not the full domain and file?

I need http://www.domain.com not http://www.domain.com/links.html

Thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Post Reply