Jump to content

SQL Query Issue (return all values, even null)


bgordon

Recommended Posts

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']. "|";
        }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.