Page 1 of 1
Forms and Multiple Arrays If you can help, I will love ya :P
Posted: Wed Aug 14, 2002 3:17 am
by MAsKrA
Ok So forget all I said before this is my prob, I have to arrays, that are passed using a checkbox on a form. One been a url, the next one been the value:
IE
theurl = /index.php
value=23424
Cant figure out how to grab that information from that array ($theurl $value) keep it together in other words the first theurl goes with the first value.
This works:
Code: Select all
foreach($theurl as $url)
{
print "$url\n";
}
But I need both $theurl and $value, so I can insert it into a gdbm file.
Posted: Wed Aug 14, 2002 9:12 am
by aaronhall
I'm not sure that I understand what you are trying to do. Please clarify - maybe I can help
-Aaron
Posted: Wed Aug 14, 2002 9:14 am
by llimllib
are you getting error messages? is it not doing what you need it to? explain, more clearly, what you're trying to accomplish, and we'll hook you up.
Posted: Wed Aug 14, 2002 7:59 pm
by MAsKrA
Damn I should stop typing after 3 am, Ok so here it goes, If you go here:
http://gamedestroyers.com/dev/counter/
I need to be able to select more than one checkbox, input more than one value in my text box, click change and insert the information in to a gdbm binary file. I have my checkbox and value boxes named like so:
Code: Select all
// $val is the url to the page with the counter ie /dev/counter/index.php
<input type=checkbox name=theurlї] value=$val>$val</td>
<input type=text name=valueї]>
Now when I process my form I cant figure out how to pack that information and insert it to the gdbm file:
Code: Select all
elseif ( ($mode == "Change") && ($theurl) && ($value) )
{
//
// We are going to change the count for a current counter.
//
$dd=dba_open("$counter",'w','gdbm') || print "No dbm\n";
$url = implode(",",$theurl);
$newcount = implode(",",$value);
$now=time();
$packed=pack("ii",$newcount,$now);
echo $url;
echo $newcount;
print("<center><strong>changed the url $url to $newcount at $now</strong></center><BR>\n");
dba_replace($url,$packed,$dd);
Now that I am using the implode(",",$theurl); I can acutally get it to insert in to one value, I just cant figure out how to make a loop so while I have a valid $theurl and a valid $value, I do the dba_replace for each.
Did I even said that correctly?
Posted: Wed Aug 14, 2002 8:01 pm
by MAsKrA
And yes the problem is, that is not inserting the information for more than one.
Thanks

Posted: Thu Aug 15, 2002 1:52 am
by aaronhall
Thank you mufasa, or mukasfra, or mukaska, orr.. whatever
Anyway, I'm not even going to read through that code becuase I'm too damn lazy. I say, write some code to track how many counters need to be changed and just make a for loop that goes through each change and edits the file. If this is what you were already doing, please ignore this message. Good luck
-Aaron
Posted: Thu Aug 15, 2002 9:31 pm
by MAsKrA
Updated information.
Ok So forget all I said before this is my prob, I have to arrays, that are passed using a checkbox on a form. One been a url, the next one been the value:
IE
theurl = /index.php
value=23424
Cant figure out how to grab that information from that array ($theurl $value) keep it together in other words the first theurl goes with the first value.
This works:
Code: Select all
foreach($theurl as $url)
{
print "$url\n";
}
But I need both $theurl and $value, so I can insert it into a gdbm file.
Posted: Fri Aug 16, 2002 1:43 am
by twigletmac
Your form may need a bit of reorganising, what does it look like?
Mac
Posted: Fri Aug 16, 2002 4:07 am
by MAsKrA
Here is the section with my entire for:
Code: Select all
<Form method=post action="<? echo $PHP_SELF; ?>">
<?php
for ($i=0;$i<count($mall); $i++)
{
$val = $mallї$i];
$key = dba_fetch($val,$dd);
$splitkey = unpack("i2int",$key);
$count = $splitkeyїint1];
$changetime = $splitkeyїint2];
print "<tr><td><input type=checkbox name=theurlї] value=$val>$val</td><td>$count</td><td><input type=text name=valueї]></td></tr>";
};
?>
</table><br>
<table border="1">
<tr>
<td align="center" valign="middle"><input type=submit value=Add name=mode></td>
<td align="center" valign="middle"><input type=submit value=Delete name=mode></td>
<td align="center" valign="middle"><input type=submit value=Change name=mode></td>
</tr>
</Form>
Posted: Fri Aug 16, 2002 4:23 am
by MAsKrA
I also tried this vor my arrays again I get it to work fine with just one like here $theurl, but cant figure out how to add the same for $value
Code: Select all
for ($i=0;$i<each($theurl); $i++)
{
$url = $theurlї$i];
$cnt = $valueї$i];
$packed=pack("ii",$value,$now);
print("<center><strong>changed the url $url to $cnt at $now</strong></center><BR>\n");
//dba_replace($theurl,$packed,$dd);
}
Posted: Fri Aug 16, 2002 4:42 am
by hob_goblin
Code: Select all
foreach($theurl as $key => $data){
echo $data;
echo $valueї$key];
}
do you know how to use foreach loops like that?
Posted: Fri Aug 16, 2002 4:48 am
by twigletmac
How about:
Code: Select all
echo '<tr><td><input type="checkbox" name="theurlї'.$i.']" value="'.$val.'">'.$val.'</td><td>'.$count.'</td><td><input type="text" name="valueї'.$i.']"></td></tr>";
Then the two values share a common associative key for sure and you can use hob_goblin's code to print out the associated pairs (and do other stuff within the foreach() loop of course).
Mac
Posted: Fri Aug 16, 2002 5:43 am
by MAsKrA
OMG THANK YOU THANK YOU THANK YOU!!!!
A Combination of those 2, did the trick for me, this is what I ended up with:
Code: Select all
print "<tr><td><input type=checkbox name=theurlї'.$i.'] value=$val>$val</td><td>$count</td><td><input type=text name=valueї'.$i.']></td></tr>";
And:
Code: Select all
foreach($theurl as $key => $data)
{
$packed=pack("ii",$valueї$key],$now);
print("<center><strong>changed the url $data to $valueї$key] at $now</strong></center><BR>\n");
dba_replace($data,$packed,$dd);
}
Again Thanks This place rocks!!!
