|
Posted by Jerry Stuckle on June 16, 2008, 1:51 pm
Please log in for more thread options
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 help 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></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></div>\n";
$htmlcode .= "<div></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
==================
|