我需要使用多个查询并将它们作为格式化的xml发送出去以用于as3目的。
当我只使用一个查询时,一切正常。
多查询操作时问题就开始了。
现在,当隐藏// XML标题时,我在屏幕上打印出一个结构,看起来很不错。
但是当标题启用时,没有任何作用!
请查看我的代码:
<?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();
?>
答案 0 :(得分:0)
早些时候我正在使用“echo”,...现在我把“printf”放在那里,但是只有一些线,我不确定这是不是原因..但现在有效。它扔给我了
“严格标准:mysqli_next_result():没有下一个结果集。请调用mysqli_more_results()/ mysqli :: more_results()来检查是否调用此函数/方法”所以寻求帮助我找到了这一行那里:
do{} while(mysqli_more_results($db) && mysqli_next_result($db));
解决了xml错误的问题。
<?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();
?>
后来我不得不序列化xml输出很简单:D
>> $i=1; and ... do {printf( "<theme name='".$i++."'>");
但现在,..如何将输出serialID与包含类别名称的数组中的元素相关联。类似......
如果name =“1”则name =“firtsArrayChild”
任何想法? 但我认为那是另一首问题的另一首歌!感谢