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.

Empfohlene Antworten

Veröffentlicht

Hi...

Ich kenn mich mit Arrays nicht so aus, aber ich brauche es um Datenbankabfragen zu minimieren.

Ich möchte das gefüllte Array ("mysql_fetch_array(query-ergebnis)") in ein neues Array schreiben. Leider wird in meinen Script nur der 1. Datensatz in das Array geschrieben. Ich benötige aber alle, welche als Ergebnis des Querys zurückgegeben wurden.

Kann mir jemand Hilfe leisten?


$ergebnis = mysql_query($sqlbefehl, $serverid);
while($fetchnews = mysql_fetch_array($ergebnis)) {
$news = array(array(
"id"=>$fetchnews[newsid],
"title"=>$fetchnews[newstitle],
"date"=>$fetchnews[newsdate],
"time"=>$fetchnews[newstime],
"user"=>$fetchnews[newsuser],
"text"=>$fetchnews[newstext]
));
}

for($x = 0; $x < count($news); $x++) {
echo $news[$x][id];
echo $news[$x][title];
echo $news[$x][date];
echo $news[$x][time];
echo $news[$x][user];
echo $news[$x][text];
}
[/PHP]

Die Funktion nutzt mir nicht wirklich viel, da ein gefülltes Array Voraussetzung dafür ist.

Ich hab derweilen mal zwei Versuche gestartet.

Die erste ist immer noch zu performancelastig, die zweite aber nicht hübsche Version funktioniert dagegen viel besser.

1. Variante:


$ergebnis = mysql_query($sqlbefehl, $serverid);
$num_fields = mysql_num_fields($ergebnis);
$x = 0;
while($fetchnews = mysql_fetch_array($ergebnis)) {
for($j = 0; $j < $num_fields; $j++){
$name = mysql_field_name($ergebnis, $j);
$news[$x][$name] = $fetchnews[$name];
}
$x++;
}
[/php]

2. Variante

[php]
$ergebnis = mysql_query($sqlbefehl, $serverid);
$x = 0;
while($fetchnews = mysql_fetch_array($ergebnis)) {
$news[$x][id] = $fetchnews[newsid];
$news[$x][title] = $fetchnews[newstitle];
$news[$x][date] = $fetchnews[newsdate];
$news[$x][time] = $fetchnews[newstime];
$news[$x][text] = $fetchnews[newstext];
$news[$x][details] = $fetchnews[newsdetail];
$news[$x][links] = $fetchnews[newslinks];
$news[$x][user] = $fetchnews[newsuser];
$x++;
}

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.