[php] dubbele resultaten met vsprintf()

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • youngster
  • Registratie: Maart 2004
  • Laatst online: 20-05 09:48
hallo,

Dit werkt bij mij:
PHP:
1
2
3
foreach ($planning as $row) {
    $str .= sprintf($format, $row[0], $row[1], $row[2], $row[3]);
}


Maar nu wil ik een variabel aantal argumenten meegeven, dus dacht ik, ik gebruik vsprintf();
PHP:
1
 $str .= vsprintf($format, $row);


Echter krijg ik hiermee dubbele resultaten terwijl $row toch echt de goede waarden bevat.
Dus ipv: 1 2 3 4
krijg ik: 1 1 2 2

Iemand enig idee hoe dit komt?

Real programmers don't comment their code... it was hard to write, it should be hard to read!


Acties:
  • 0 Henk 'm!

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06 13:31

drm

f0pc0dert

't Is wel handig als je ook even vertelt wat de $format variabele bevat.

edit:
Overigens: ik neem aan dat je die vsprintf () wel ook in een dergelijke foreach zet?

[ Voor 44% gewijzigd door drm op 22-03-2004 16:28 ]

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Acties:
  • 0 Henk 'm!

  • youngster
  • Registratie: Maart 2004
  • Laatst online: 20-05 09:48
Ok, hier het hele stukje code, $format heeft natuurlijk ook een variabele inhoud.
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$planning = $this->db->db_select($query);

$str = "[table]\n";
$format = "[row] [img=".IMAGE_PATH."bullet.png]bullet[/img]";
for($i=0; $i<count($fields); $i++){  //$fields bevat de velden die in de query zijn gestopt
    $format .= "%s | ";
}
$format .= "\n";
$str .= "[row] \n";

foreach ($planning as $row) {
    $str .= sprintf($format, $row[0], $row[1], $row[2], $row[3]);
}   
$str .= "[/table]\n";

Real programmers don't comment their code... it was hard to write, it should be hard to read!


Acties:
  • 0 Henk 'm!

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

code:
1
$str .= vsprintf($format, $row);

Je impliceert met die code dat je het in een foreach hebt staan, aangezien je $row gebruikt. Dat moet iig niet. Verder zie ik niet wat het zou kunnen zijn...

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Acties:
  • 0 Henk 'm!

  • youngster
  • Registratie: Maart 2004
  • Laatst online: 20-05 09:48
'k Heb de oplossing zelf al gevonden....
$row was een MYSQL_BOTH-array O-)

Real programmers don't comment their code... it was hard to write, it should be hard to read!