I found this link fetch_assoc() works only once in a loop but not solved my problem I need to fetch 2 diff tables and result the select something
to XML sitemap
i need the result to be inside each others:
Code:
<?php
$my_sqli = new mysqli('localhost', 'root', '', 'my_db') or die(mysqli_error($my_sqli));
$data1 = $my_sqli->query("select urls from category_table where locale = 'en' AND NOT( trans_url <=> NULL); ") or die($my_sqli->error);
$data2 = $my_sqli->query("select name from something_table where locale = 'en'") or die($my_sqli->error);
$rows2 = $data2->fetch_all(MYSQLI_ASSOC);
header("Content-Type: application/xml; charset='utf-8'");
$xml_str = '<!--?xml version="1.0" encoding="iso-8859-1"?-->'. PHP_EOL;
$xml_str .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . PHP_EOL;
while ($row = $data1->fetch_assoc()) {
$encoded_url = $row['urls'];
$xml_str .= '<url>' . PHP_EOL;
$xml_str .= '<loc>' . htmlspecialchars($encoded_url) . '</loc>' . PHP_EOL;
while ($row2 = $data2->fetch_assoc()) {
$encoded_url2 = $row2['name'];
$xml_str .= '<loc>' . htmlspecialchars($encoded_url2) . '</loc>' . PHP_EOL;
} // end child loop
// reset $data2 result pointer
$xml_str .= '<lastmod>'. date(DATE_ATOM, time()) .'</lastmod>' .PHP_EOL;
$xml_str .= '</url>' . PHP_EOL;
$data2->data_seek(0);
}
$xml_str .= '</urlset>';
$dom = new DOMDocument('1.0', 'iso-8859-1');
$dom->preserveWhiteSpace = false;
$dom->loadXML($xml_str);
echo $xml_str;
$dom->save('./sitemap.xml');
Desired Output:
category_table 1
something_table 1
category_table 2
something_table 2
category_table 3
something_table 3
category_table 4
something_table 4
. . . .
Note:
2 tables doesn't have the same result (No. of result) .