subh Posted October 28, 2009 Share Posted October 28, 2009 I have a beginner in PHP and am facing a strange issue. I have a SQL query like this SELECT fq_customer.customer_id, fq_customer.customer_name, fq_user_customer_mapping.user_id, IF(!ISNULL(fq_user_customer_mapping.user_id), 'true', 'false') AS is_user_customer FROM fq_customer LEFT OUTER JOIN fq_user_customer_mapping ON fq_customer.customer_id = fq_user_customer_mapping.customer_id AND fq_user_customer_mapping.user_id=(SELECT user_id FROM fq_users WHERE user_name='$user') When I run the query on my SQL client, i get results like this customer_id customer_name user_id is_user_customer --------------------------------------------------------- "0" "ABC Inc" NULL "false" "11" "XYZ Inc" NULL "false" "13" "SDG Inc" NULL "false" "12" "PQR Inc" "1" "true" As you can see, the first 3 rows have 'user_id' as NULL and hence 'is_user_customer' is false, but this output changes when i save it using the saveXML() call in php code. In my PHP file, I have this while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $dom->createElement("customer"); $newnode = $parnode->appendChild($node); $newnode->setAttribute("customer_id",$row['customer_id']); $newnode->setAttribute("customer_name", $row['customer_name']); $newnode->setAttribute("is_user_customer", $row['is_user_customer']); $newnode->setAttribute("user_id", $row['user_id']); } echo $dom->saveXML(); But when I open the PHP to see the DOM, I see like this <customers> <customer customer_id="0" customer_name="ABC Inc." is_user_customer="false" user_id=""/> <customer customer_id="11" customer_name="XYZ Inc" is_user_customer="true" user_id="1"/> <customer customer_id="13" customer_name="SDG Inc" is_user_customer="true" user_id="1"/> <customer customer_id="12" customer_name="PQR Inc" is_user_customer="true" user_id="1"/> </customers> Now if you see, the first row comes fine but after that it sets the user_id as '1' whereas it should have set that only for the 4th node. Please let me know what am I doing wrong. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/179296-strange-error-mysql-query-and-savexml/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.