PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > with arrays
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
with arrays

Réponse
 
LinkBack Outils de la discussion
Vieux 16/06/2008, 16h43   #1
inexion
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with arrays

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!


  Réponse avec citation
Vieux 16/06/2008, 18h51   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with arrays

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
==================

  Réponse avec citation
Vieux 16/06/2008, 19h46   #3
inexion
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with arrays

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
  Réponse avec citation
Vieux 16/06/2008, 22h20   #4
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with arrays

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
==================

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h41.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12094 seconds with 12 queries