Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mySQL -> PHP -> XML very confusing!

Status
Not open for further replies.

cocoadev

Programmer
Nov 11, 2003
4
GB

any idea why this behaves unexpectedly????...



<?
$sHost = &quot;localhost&quot;;
$sUser = &quot;*****&quot;;
$sPass = &quot;*****&quot;;

mysql_connect($sHost,$sUser,$sPass);
mysql_select_db(&quot;*****&quot;);

$combined = mysql_query(&quot;SELECT combocode, combotitle, combodesc, comboimage FROM combined WHERE combined.combocode = 1&quot;);
$product = mysql_query(&quot;SELECT title, description , material , colours FROM product WHERE product.combocode = 1&quot;);
$prices = mysql_query(&quot;SELECT price FROM product, details WHERE product.combocode = 1 AND details.productID = product.productID&quot;);
$sizes = mysql_query(&quot;SELECT sizes FROM product, size WHERE product.combocode = 1 AND product.sizeID = size.sizeID&quot;);


while($combinedRow = mysql_fetch_assoc ($combined)){
listRow($combinedRow);

while($productRow = mysql_fetch_assoc($product)){
listRow($productRow);

while($pricesRow = mysql_fetch_assoc($prices)){
listRow($pricesRow);

while($sizesRow = mysql_fetch_assoc($sizes)){
listRow($sizesRow);
}
}
}
}


function listRow($row){
foreach ($row as $key => $value) {
$hold = strtoupper(&quot;<$key>&quot;);
$hold .= $value;
$hold .= strtoupper(&quot;</$key>&quot;).&quot;\n&quot;;
}
echo $hold;
}
?>

///////////////////////////////////////////////////////////////////
produces the output...


<COLOURS>pink, black, blue</COLOURS>
<COMBOCODE>4</COMBOCODE>
<PRICE>22.99</PRICE>
<SIZES>one size</SIZES>
<SIZES>32, 36, 38, 40</SIZES>
<PRICE>9.99</PRICE>
<COLOURS>red</COLOURS>

there is missing information, like all the info from the table 'combined' bar the 'combocode' field.

However, if i exchange the 'listRow' function for this(+ make appropriate changes to calling functions)...


///////////////////////////////////////////
function listRow($query, $row){

if(!mysql_num_rows($query)) {
return &quot;EMPTY&quot;;
} else {
$iNumFields = mysql_num_fields($query);
$iNumRes = mysql_num_rows($query);

while($iRow = mysql_fetch_array($query)) {
$sRet = &quot; <RESULT>\n&quot;;

for($a = 0; $a < $iNumFields; $a++) {
$sTmp = mysql_field_name($query,$a);
$sRet .= &quot; &quot;.strtoupper(&quot;<$sTmp>&quot;);
$sRet .= $iRow[&quot;$sTmp&quot;];
$sRet .= strtoupper(&quot;</$sTmp>&quot;).&quot;\n&quot;;
}

$sRet .= &quot; </RESULT>\n&quot;;
}

}
echo $sRet;
}

///////////////////////////////////////////////


i get the output...

<RESULT>
<PRODUCTID>1</PRODUCTID>
<TITLE>tits</TITLE>
<DESCRIPTION>false large tits</DESCRIPTION>
<MATERIAL>rubber</MATERIAL>
<COLOURS>red</COLOURS>
</RESULT>
<RESULT>
<PRICE>9.99</PRICE>
</RESULT>
<RESULT>
<SIZES>32, 36, 38, 40</SIZES>
</RESULT>


...any ideas, i am very confused.

thanks, ben.
 
I have sorted it out, it was simple...

function listRow($row){
  foreach ($row as $key => $value) {
    $hold = strtoupper(&quot;<$key>&quot;);
    $hold .= $value;
    $hold .= strtoupper(&quot;</$key>&quot;).&quot;\n&quot;;
  echo $hold;
 }
   
}
?>

instead of...

function listRow($row){
  foreach ($row as $key => $value) {
    $hold = strtoupper(&quot;<$key>&quot;);
    $hold .= $value;
    $hold .= strtoupper(&quot;</$key>&quot;).&quot;\n&quot;;
   }
   echo $hold;
}
?>
 
incidently, am i making a mountain out of a molehill here? surely there an easier way to output xml?????? I am a newbie, forgive me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top