0

I need to use multiple queries and send them out as well formed xml for as3 purposes.

When I use only one query everything works fine.

Problem starts when multi-query operates.

Right now when //XML header is hidden I get a structure printed on screen and it looks good.

But when header goes enabled, nothing works!

Please take a look at my code:

<?php   
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
$dbName = "test";
$dbTable = "pizzaroma";

$mysqli = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName);
if ($mysqli->connect_errno)
echo "la conection ha fallado: ".$mysqli->connect_errno;

$query = "SELECT * FROM ".$dbTable." WHERE cat='pizza' AND act='1'  ORDER BY ID ASC; ";
$query .= "SELECT * FROM ".$dbTable." WHERE cat='pasta' AND act='1'  ORDER BY ID ASC; ";    

if ($mysqli->multi_query($query)) {
     // header("Content-type: text/xml");
      echo "<?xml version='1.0' encoding='UTF-8'?>";
      echo "<pics>";
do { 
    echo "<theme name='temporaly'>";
    if ($result = $mysqli->store_result()) {

         while ($row = $result->fetch_assoc()) {

           echo "<pic name='".$row['NAME']."'  desc='".$row['DESCES']."' price='".$row['PRICE']."'/>";
           echo "</pic>";
        }
        $result->free();
    }
         echo "</theme>";
    if ($mysqli->more_results()) {          
    }

    } 
    while ($mysqli->next_result());  
        echo "</pics>";
}

    $mysqli->close();
    ?>
ArK
  • 20,698
  • 67
  • 109
  • 136
  • I see this so often in PHP and other languages. Don't build a string concatenation of XML. PHP has dedicated classes like SimpleXML and DomDocument with `createElement()`, `appendChild()`, and other methods. Remember XML is not a text file. – Parfait Jul 25 '16 at 13:37
  • Also, please explain or better show: *But when header goes enabled, nothing works!*. Is screen echo cutting XML off with multiple queries? This might be an as3 issue not PHP. – Parfait Jul 25 '16 at 13:44
  • thank you for response Parfait! so, I should use another method else than concadenation. i will take a a look at them later ( simpleXML),.. responding to secon part ,.. by now i am executing the php in browser ,.. when works i go to as3 ( but this only happends with single line sentenced query/mysql ),...... hey! I was about to send it all but before I ve touched here and there,.. suddenly everything flyes like a charm. here is what i did,.. – Pixel2Media Jul 25 '16 at 19:11

1 Answers1

0

earlier i were using "echo",.. now instead ive put "printf" there,.. but only some lines, i am not sure if that was the reason.. but now works. it was throwing me the

"Strict Standards: mysqli_next_result(): There is no next result set. Please, call mysqli_more_results()/mysqli::more_results() to check whether to call this function/method" so looking for help i have found this line there :

 do{} while(mysqli_more_results($db) && mysqli_next_result($db));

that solved the problem for xml error.

<?php


$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
$dbName = "test";
$dbTable = "pizzaroma";

$mysqli = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName);
if ($mysqli->connect_errno)
echo "la conection ha fallado: ".$mysqli->connect_errno;

$query = "SELECT * FROM ".$dbTable." WHERE cat='pizza' AND act='1'  ORDER BY ID ASC; ";
$query .= "SELECT * FROM ".$dbTable." WHERE cat='pasta' AND act='1'  ORDER BY ID ASC; ";
$query .= "SELECT * FROM ".$dbTable." WHERE cat='carne' AND act='1'  ORDER BY ID ASC; ";


if ($mysqli->multi_query($query)) {
      header("Content-type: text/xml");
      printf( "<?xml version='1.0' encoding='UTF-8'?>");
      printf( "<pics>");
do { 
    printf( "<theme name='temporaly'>");
    if ($result = $mysqli->store_result()) {

         while ($row = $result->fetch_assoc()) {

           echo "<pic name='".$row['NAME']."'/>";

        }
        $result->free();
    }
         echo "</theme>";

    } 
    while (mysqli_more_results($mysqli) && mysqli_next_result($mysqli));

        echo "</pics>";
}

    $mysqli->close();
    ?>

later on i´ve had to serialize the xml output it was easy :D

>> $i=1;   and ... do {printf( "<theme name='".$i++."'>");

but now ,.. how do I associate output serialIDs to elements from array that contains category names. something like...

if name="1" then name="firtsArrayChild"

any idea? but i think that is another song for another question out there! thanks