bgordon Posted October 17, 2007 Share Posted October 17, 2007 Here is some code I have pieced together to do a | delimited dump of all my data from a mysql table. My issue is that it only returns fields that have values. Since I am exporting to a delimited file that I intend to open and sanitize in excel, I need all the fields for each row, even if empty, or else my data gets all skewed and won't line up for me in columns. Can any of you gurus point me in the right direction? I want the output to be like this: data1|data2|data3|||data6||data8 and NOT data1|data2|data3|data6|data8 like it does now. $sSQL2 = "SELECT f.fID,sValue FROM ".PREFIX."products_fields AS p, `".PREFIX."fields` AS f WHERE p.pID=".$row['id']." AND f.fSeen='Y' AND p.fID=f.fID ORDER BY f.fOrder ASC"; $result2=$db->query($sSQL2); $i=0; while ($rs=$result2->fetch()) { $sql="SELECT fID,fName,fType FROM `".PREFIX."fields` WHERE fID='".$rs['fID']."' "; $result3=$db->query($sql); $rs2=$result3->fetch(); if(strpos($rs['sValue'], "|")) { $rs['sValue'] = explode("|", $rs['sValue']); } echo $rs2['fName']. "|" . $rs['sValue']. "|"; } Quote Link to comment https://forums.phpfreaks.com/topic/73586-sql-query-issue-return-all-values-even-null/ Share on other sites More sharing options...
fenway Posted October 17, 2007 Share Posted October 17, 2007 You need a LEFT JOIN. Quote Link to comment https://forums.phpfreaks.com/topic/73586-sql-query-issue-return-all-values-even-null/#findComment-371536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.