using simultaneous arrays

This is a discussion on using simultaneous arrays within the PHP Language forums, part of the PHP Programming Forums category; I have a table with each column containing the following form objects - combobox, hidden field, textarea, and tick box. I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-28-2006
Ian Davies
 
Posts: n/a
Default using simultaneous arrays

I have a table with each column containing the following form objects -
combobox, hidden field, textarea, and tick box. I have created arrays from
each of these columns and now I wish to use the arrays altogether, taking
each array element in order to use in an sql statement
Does anyone know how to use arrays simultaneously
eg
Array1 - 1,2,3
Array2 - text1,text2,text3
Array3 - 31,56,34
Aray4- 1,1,0

used in a loop to populate the following SQLs
SQL="UPDATE mytable SET fieldA=Array2[0], fieldB=Array3[0], fieldC=Array4[0]
WHERE Index=Array1[0]"
SQL="UPDATE mytable SET fieldA=Array2[1], fieldB=Array3[1], fieldC=Array4[1]
WHERE Index=Array1[1]"
etc
for all the elements in the array

Ian


Reply With Quote
  #2 (permalink)  
Old 07-28-2006
Jay
 
Posts: n/a
Default Re: using simultaneous arrays

Hi Ian

You could simply use a multidimensional array ;)

Like

$AllItems = array();

for($i = 0; $i < 10; ++$i)
{
$TestData = Array($i,$i*2,"Foo, ");
array_push($AllItems, $TestData );
}

Then you can access your array via $AllItems[ any valid index]

maybe this is what you want

Best regards

Reply With Quote
  #3 (permalink)  
Old 07-28-2006
Miguel Cruz
 
Posts: n/a
Default Re: using simultaneous arrays

"Ian Davies" <iandan.dav@virgin.net> wrote:
> I have a table with each column containing the following form objects -
> combobox, hidden field, textarea, and tick box. I have created arrays from
> each of these columns and now I wish to use the arrays altogether, taking
> each array element in order to use in an sql statement
> Does anyone know how to use arrays simultaneously
> eg
> Array1 - 1,2,3
> Array2 - text1,text2,text3
> Array3 - 31,56,34
> Aray4- 1,1,0
>
> used in a loop to populate the following SQLs
> SQL="UPDATE mytable SET fieldA=Array2[0], fieldB=Array3[0], fieldC=Array4[0]
> WHERE Index=Array1[0]"
> SQL="UPDATE mytable SET fieldA=Array2[1], fieldB=Array3[1], fieldC=Array4[1]
> WHERE Index=Array1[1]"
> etc
> for all the elements in the array


<?

for ($i = 0; $i < count($Array1); $i++)
{
$sql = "update mytable
set fieldA = {$Array2[$i]},
fieldB = {$Array3[$i]},
fieldC = {$Array4[$i]},
where Index = {$Array1[$i]}";
mysql_query($sql);
}

?>

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Reply With Quote
  #4 (permalink)  
Old 07-28-2006
Ian Davies
 
Posts: n/a
Default Re: using simultaneous arrays

cheers
thanks
That works fine
Ian


"Miguel Cruz" <spam@admin.u.nu> wrote in message
news:spam-16BC9D.00511229072006@localhost...
> "Ian Davies" <iandan.dav@virgin.net> wrote:
> > I have a table with each column containing the following form objects -
> > combobox, hidden field, textarea, and tick box. I have created arrays

from
> > each of these columns and now I wish to use the arrays altogether,

taking
> > each array element in order to use in an sql statement
> > Does anyone know how to use arrays simultaneously
> > eg
> > Array1 - 1,2,3
> > Array2 - text1,text2,text3
> > Array3 - 31,56,34
> > Aray4- 1,1,0
> >
> > used in a loop to populate the following SQLs
> > SQL="UPDATE mytable SET fieldA=Array2[0], fieldB=Array3[0],

fieldC=Array4[0]
> > WHERE Index=Array1[0]"
> > SQL="UPDATE mytable SET fieldA=Array2[1], fieldB=Array3[1],

fieldC=Array4[1]
> > WHERE Index=Array1[1]"
> > etc
> > for all the elements in the array

>
> <?
>
> for ($i = 0; $i < count($Array1); $i++)
> {
> $sql = "update mytable
> set fieldA = {$Array2[$i]},
> fieldB = {$Array3[$i]},
> fieldC = {$Array4[$i]},
> where Index = {$Array1[$i]}";
> mysql_query($sql);
> }
>
> ?>
>
> miguel
> --
> Photos from 40 countries on 5 continents: http://travel.u.nu
> Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
> Airports of the world: http://airport.u.nu



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:14 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0