|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I will just give an example of what my code looks like and what I'd like to accomplish. I have a few arrays that get filled up with mysql table values, and one thats predefined. my goal is to generate text files with this so heres how it works... $array1 = sql data; $array2 = sql data; $arr['html code'] = "<html>\n <body>\n <div>(one array1 value at a time is filled into this div)</div>\n <br />\n <div>(one array2 value at a time is filled into this div)</div>\n </html>"; for($i = 0; $i < sizeof($array1); $i++) { $fwrite(....); } so then, my final text file looks like this: array1_value1 array1_value2 array1_value3 ........ array2_value1 array2_value2 array2_value3 ......... I need with getting the array values from 1 & 2 into the $array['html code'] so that when the loop happens it can write however many sql entries there are. thanks! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
inexion wrote:
> Hi, > > I will just give an example of what my code looks like and what I'd > like to accomplish. > > > I have a few arrays that get filled up with mysql table values, and > one thats predefined. my goal is to generate text files with this so > heres how it works... > > $array1 = sql data; > $array2 = sql data; > > $arr['html code'] = "<html>\n > <body>\n > <div>(one array1 value at a time is filled into this div)</div>\n > <br />\n > <div>(one array2 value at a time is filled into this div)</div>\n > </html>"; > > for($i = 0; $i < sizeof($array1); $i++) > { > $fwrite(....); > } > > > so then, my final text file looks like this: > > array1_value1 > array1_value2 > array1_value3 > ....... > > array2_value1 > array2_value2 > array2_value3 > ........ > > I need with getting the array values from 1 & 2 into the > $array['html code'] so that when the loop happens it can write however > many sql entries there are. thanks! > > > I guess my first question would be - why use $array1 and $array2? I would think something like: $array[0] = sql data $array[1] = sql data Now you can reference them via $array[0][0] $array[0][1] $array[0][2] $array[1][0] $array[1][1] $array[1][2] and so on. And a simple loop such as The next question - your sample output shows you want it in the above format, in which case the following would work: for ($i = 0; $i < count($array); $i++) for ($j = 0; $j < count($array[$i]); $j++) $htmlcode .= "<div>{$array[$i][$j]}</div>\n"; But your sample code seems to indicate you want it in the following format: $array[0][0] $array[1][0] $array[0][1] $array[1][1] $array[0][2] $array[1][2] In which case you'd want something like: for ($i = 0; $i < count($array[0]); $i++) { $htmlcode .= "<div>{$array[0][$i]}</div>\n"; $htmlcode .= "<div>{$array[1][$i]}</div>\n"; } (In the latter case, if the arrays may be different sizes you'll have to handle that, also). Also, I'm wondering - why are you putting the code in an array ($arr['html code'])? All you need is a string (which is what I did above). -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
If I use that method, it only prints out the first element of each, I
need all 2000+ to be output.....not sure why, but the count goes from 2303 to 1 if I change the array to $array[0]...etc thanks |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
inexion wrote:
> If I use that method, it only prints out the first element of each, I > need all 2000+ to be output.....not sure why, but the count goes from > 2303 to 1 if I change the array to $array[0]...etc > > thanks > No, it will print out all elements of the array. Try the code I gave you. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
![]() |
| Outils de la discussion | |
|
|