Umwandlung habe ich ein Skript Daten aus zwei Tabellen zu extrahieren matieres
und sous_matieres
aber es ist geschrieben für PDO, ich brauche es für MySQLi arbeiten:Ergebnisse nicht angezeigt, nachdem PDO Abfrage MySQLi
$stmt = $pdo->query('SELECT
m.id AS m_id, m.url AS m_url, m.title AS m_title,
s.id AS s_id, s.url AS s_url, s.title AS s_title
FROM matieres m
INNER JOIN sous_matieres s ON m.url = s.parent');
while ($row = $stmt->fetchObject()) {
$matieres[$row->m_id]['url'] = $row->m_url;
$matieres[$row->m_id]['title'] = $row->m_title;
$matieres[$row->m_id]['sous_matieres'][$row->s_id] = $row;
}
foreach ($matieres as $m_id => $matiere) {
echo "<h2>$matiere[title]</h2>";
foreach ($matiere['sous_matieres'] as $id => $sm) {
echo "<div>
<a href='{$sm->s_url}'>{$sm->s_title}</a>
</div>";
}
}
Mein neuer mySQLi Code, der nichts trotz der beiden Tabellen Daten zeigt:
$query = 'SELECT
m.id AS m_id, m.url AS m_url, m.title AS m_title,
s.id AS s_id, s.url AS s_url, s.title AS s_title
FROM matieres m
INNER JOIN sous_matieres s ON m.url = s.parent';
$stmt = $mysqli->query($query);
$stmt->execute();
$stmt->store_result();
while ($row = $stmt->fetch()) {
$matieres[$row->m_id]['url'] = $row->m_url;
$matieres[$row->m_id]['title'] = $row->m_title;
$matieres[$row->m_id]['sous_matieres'][$row->s_id] = $row;
}
foreach ($matieres as $m_id => $matiere) {
echo "<h2>$matiere[title]</h2>";
foreach ($matiere['sous_matieres'] as $id => $sm) {
echo "<div>
<a href='{$sm->s_url}'>{$sm->s_title}</a>
</div>";
}
}
I don Ich weiß nicht, ob es $stmt->bind_result()
und die Variable im Inneren fehlt. Wie bei normalen mySQLi-Abfragen (ohne Joins) muss ich die ausgewählten Spaltennamen als Variable innerhalb des $stmt->bind_result()
Ich denke, $ mysqli-> query() 'gibt bereits die ausgeführte Anweisung zurück (außer seltsamer Wrapper). Aufruf von '-> execute()' kann Dinge tun, die Sie nicht beabsichtigen ... als ... wenn Sie ... ausführen, fangen Sie den Rückgabewert tatsächlich zu Debugging-Zwecken ab. (Wie auch immer, ich bin unsicher, warum Sie zu mysqli wechseln würden) – Jakumi