Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

php array befüllen

Empfohlene Antworten

Veröffentlicht

guten morgen allerseits,

ich habe folgendes problem:

ich hab ne datenbank, aus der ich werte raushole(das klappt auch) und diese möchte ich wie folgt in ein array schreiben:


while(pg_fetch_row($Result))
{
$wert = pg_result($Result,"db-feld");

$daten = array( $wert =>10 );

}

foreach($daten as $key=>$wert){
print $key = $wert."<br>";
}
[/PHP]

1. frage:

ist das mit dem array befüllen so richtig? ich bekomme von der db für $wert 10 strings. wird das array dann so befüllt: string1 wert 10, string2 wert 10 usw.

oder ist da schon ein fehler drin?

2. frage wenn ich das array dann ausgebe mit foreach müsste doch folgendes rauskommen,oder? string1 = 10, string2 = 10...

ich bekomme nur einmal die 10. er müsste mir dann aber doch 10 * die 10 mit zugehörigem string ausgeben, da ich ja auch 10 strings in der db hab.

was mache ich falsch? kann mir jmd helfen?

danke korea1

Servus!

Wieso liest Du das Recordset aus (ist ja schon ein Array) und schreibst es in ein anderes Array? Du kannst doch in der oberen while-Schleife gleich die Ausgaben machen.

Und das mit dem 10 und dem 10*10 habe ich nicht umrissen. Das müsstest Du noch mal konkretisieren...

[EDIT]

Stop, Du erzeugst doch mit jedem Aufruf von array(blubb => bla) ein neues Array. Was Du suchst, ist array_push, glaube ich.

Schau Dir mal das PHP-Manual auf der Seite http://www.php.net an. Das kannst Du auch downloaden.

[/EDIT]

Peter



$daten = "";

while(pg_fetch_row($Result))
{
$wert = pg_result($Result,"db-feld");

$daten[$wert] = 10;
}
[/PHP]

korea1

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.