PSD-Tutorials.de
Forum für Design, Fotografie & Bildbearbeitung
Tutkit
Agentur
Hilfe
Kontakt
Start
Forum
Aktuelles
Besonderer Inhalt
Foren durchsuchen
Tutorials
News
Anmelden
Kostenlos registrieren
Aktuelles
Suche
Suche
Nur Titel durchsuchen
Von:
Menü
Anmelden
Kostenlos registrieren
App installieren
Installieren
JavaScript ist deaktiviert. Für eine bessere Darstellung aktiviere bitte JavaScript in deinem Browser, bevor du fortfährst.
Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden.
Du solltest ein Upgrade durchführen oder einen
alternativen Browser
verwenden.
Antworten auf deine Fragen:
Neues Thema erstellen
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
PHP implode, Trennzeichen mit Variable
Beitrag
<blockquote data-quote="owieortho" data-source="post: 2449286" data-attributes="member: 443210"><p>Danke @<span style="font-size: 15px"></span></p><p><span style="font-size: 15px">So ganz durch bin ich noch nicht. Vielleicht wird es verständlicher, wenn ich den Hintergrund beschreibe. Ich habe zwei Datentabellen:</span></p><p><span style="font-size: 15px">Tabelle 1:</span></p><p><span style="font-size: 15px">id | Frage</span></p><p><span style="font-size: 15px">---------------------</span></p><p><span style="font-size: 15px">q1 | Text Frage 1</span></p><p><span style="font-size: 15px">q2 | Text Frage 2</span></p><p></p><p><span style="font-size: 15px">Tabelle 2:</span></p><p><span style="font-size: 15px">... | q1 | q2 | ...</span></p><p><span style="font-size: 15px">--------------------</span></p><p><span style="font-size: 15px">... | Zahl | Zahl | ...</span></p><p><span style="font-size: 15px">... | Zahl | Zahl | ...</span></p><p></p><p><span style="font-size: 15px">Mein gewünschtes Ergebnis soll eine Tabelle sein:</span></p><p><span style="font-size: 15px"><span style="font-size: 15px">Text Frage 1 | Mittelwert Zahlen q1</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px">Text Frage 2 | Mittelwert Zahlen q2</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px">......usw.</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px">Ich habe den Rat befolgt und jetzt den String für die SELECTS nicht mit implode konstruiert. Aber wie kriege ich jetzt die separaten foreach-Schleifen abwechselnd zur Füllung der zweiten Tabellenzelle jeder Zeile?</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px">[php]$sql = "SELECT q, de FROM fragen WHERE `type` = 'radio'";</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> $count = mysql_query ($sql);</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> while ($row = mysql_fetch_array ($count))</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> $rows[] = $row;</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> </span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> foreach ($rows AS $pos) {</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> $p = $pos['q'];</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> $select = $select."AVG(`".$p."`) AS avg".$p.", ";</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> $where = $where."`".$p."`<>0 AND `".$p."`<6 AND ";</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px">}</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px">$select = rtrim($select,", ");</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px">$where = rtrim($where,", AND ");</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"></span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> $sql = "SELECT ".$select." FROM `codes` WHERE ".$where;</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"></span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> $result = mysql_query ($sql);</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> while ($avg = mysql_fetch_array ($result))</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> $rows2[] = $avg;</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> </span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> foreach ($rows AS $row) {</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> $question = $row['de'];</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> echo "<tr>\n<td>".$question."</td>\n<td>?????????</td></tr>\n";</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px"> }[/php]</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px">Herzlichen Dank</span></span></p><p><span style="font-size: 15px"><span style="font-size: 15px">O.</span></span></p><p><span style="font-size: 15px"></span></p></blockquote><p></p>
[QUOTE="owieortho, post: 2449286, member: 443210"] Danke @[SIZE=4][B][/B] So ganz durch bin ich noch nicht. Vielleicht wird es verständlicher, wenn ich den Hintergrund beschreibe. Ich habe zwei Datentabellen: Tabelle 1: id | Frage --------------------- q1 | Text Frage 1 q2 | Text Frage 2[/SIZE] [SIZE=4]Tabelle 2: ... | q1 | q2 | ... -------------------- ... | Zahl | Zahl | ... ... | Zahl | Zahl | ...[/SIZE] [SIZE=4]Mein gewünschtes Ergebnis soll eine Tabelle sein: [SIZE=4]Text Frage 1 | Mittelwert Zahlen q1 Text Frage 2 | Mittelwert Zahlen q2 ......usw. Ich habe den Rat befolgt und jetzt den String für die SELECTS nicht mit implode konstruiert. Aber wie kriege ich jetzt die separaten foreach-Schleifen abwechselnd zur Füllung der zweiten Tabellenzelle jeder Zeile? [php]$sql = "SELECT q, de FROM fragen WHERE `type` = 'radio'"; $count = mysql_query ($sql); while ($row = mysql_fetch_array ($count)) $rows[] = $row; foreach ($rows AS $pos) { $p = $pos['q']; $select = $select."AVG(`".$p."`) AS avg".$p.", "; $where = $where."`".$p."`<>0 AND `".$p."`<6 AND "; } $select = rtrim($select,", "); $where = rtrim($where,", AND "); $sql = "SELECT ".$select." FROM `codes` WHERE ".$where; $result = mysql_query ($sql); while ($avg = mysql_fetch_array ($result)) $rows2[] = $avg; foreach ($rows AS $row) { $question = $row['de']; echo "<tr>\n<td>".$question."</td>\n<td>?????????</td></tr>\n"; }[/php] Herzlichen Dank O.[/SIZE] [/SIZE] [/QUOTE]
Bilder bitte
hier hochladen
und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Zitate einfügen…
Authentifizierung
Wenn ▲ = 5, ▼ = 2 und ■ = 7, was ist ▲ × ▼ + ■?
Antworten
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
PHP implode, Trennzeichen mit Variable
Oben