Jump to content

SQL Query Issue (return all values, even null)


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.