Getting loop-generated values
Moderator: General Moderators
-
tristanlee85
- Forum Contributor
- Posts: 172
- Joined: Fri Dec 19, 2003 7:28 am
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
And why exactly do you suspect that the string would be passed that way?tristanlee85 wrote:Yeh, I've been using that, but I know how to split it when there is a common explode characher like ":", but with a string like this: 115528209812345418419420421422423424425426427428
Red being the date, blue being the zip, and green being the door numbers.
-
tristanlee85
- Forum Contributor
- Posts: 172
- Joined: Fri Dec 19, 2003 7:28 am
Because when I that's what it outputs.
Code: Select all
echo ${$key};I don't know why it would end up like that......tristanlee85 wrote:Yeh, I've been using that, but I know how to split it when there is a common explode characher like ":", but with a string like this: 115528209812345418419420421422423424425426427428
Red being the date, blue being the zip, and green being the door numbers.
but
Code: Select all
$strlen = strlen($that_string);
$date = substr($that_string,0,10);
$zip = substr($that_string,10,5);
$door = substr($that_string,$strlen-($strlen-15),$strlen); // i think[edit] Nvm, just read the posts above mine. Fast posters.
[edit2] Nvm edit 1. I guess I only read the first page. Back to bed I go.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
You're going about that the wrong way. As you echo, since there is nothing else being echoed, PHP, as it normally does, is echoing out exactly what you tell it to do. But that stage is not for echoing, it is for assigning. If you want to see exactly what is being output to each var, do this...tristanlee85 wrote:Because when Ithat's what it outputs.Code: Select all
echo ${$key};
Code: Select all
<?php
foreach ($_POST as $key => $value)
{
// this tells you what is getting assigning to what var
echo '<p>The var$' . $key . ' will have a value of ' . $value . '...</p>';
// This is actually handling assignments
${$key} = $value;
}
?>-
tristanlee85
- Forum Contributor
- Posts: 172
- Joined: Fri Dec 19, 2003 7:28 am
I did the "echo" part to see what my results were. I got this:
That's all good and pretty much what I want. So, since I'm using this loop to post values into a databse, how would I do something like this:
[door_number] = the value of $door_number***
[misload_string] = the value of $zips***
[unix_date] = the value of $date
Code: Select all
The var $date will have a value of 1155610344...
The var $zips418 will have a value of 12345...
The var $door_number418 will have a value of 418...
The var $zips419 will have a value of 12345...
The var $door_number419 will have a value of 419...
The var $zips420 will have a value of 12345...
The var $door_number420 will have a value of 420...
The var $zips421 will have a value of 12345...
The var $door_number421 will have a value of 421...
The var $zips422 will have a value of 12345...
The var $door_number422 will have a value of 422...
The var $zips423 will have a value of 12345...
The var $door_number423 will have a value of 423...
The var $zips424 will have a value of 12345...
The var $door_number424 will have a value of 424...
The var $zips425 will have a value of 12345...
The var $door_number425 will have a value of 425...
The var $zips426 will have a value of 12345...
The var $door_number426 will have a value of 426...
The var $zips427 will have a value of 12345...
The var $door_number427 will have a value of 427...
The var $zips428 will have a value of 12345...
The var $door_number428 will have a value of 428...
The var $post will have a value of ...Code: Select all
$query1 = "INSERT INTO misloads VALUES ('','[door_number]','[misload_string]','[unix_date]')";[misload_string] = the value of $zips***
[unix_date] = the value of $date
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
tristanlee85
- Forum Contributor
- Posts: 172
- Joined: Fri Dec 19, 2003 7:28 am
That's what I was meaning. Sorry, I had posted the loop code, but edited my post and accidentally removed it. I was meaning something like this:
But then of course I'd have to make sure to store the $_POST key $date ouside the loop since it won't be changing sequence if more or less doors are being posted so I can use the variable for the query through the loop. I'd also need to validate the loop so that the key $post is ignored when getting the $_POST values.
Code: Select all
foreach ($_POST as $key => $value)
{
// This is actually handling assignments
${$key} = $value;
$query = "INSERT INTO misloads VALUES ('','[door_number]','[misload_string]','[unix_date]')";
mysql_query($query);
}