[Typo3-dev] sql question ;)

JoH info at cybercraft.de
Mon Apr 26 12:25:06 CEST 2004


>i want to make a sql condition like this
>
>AND checkboxfield=16
>
>i have severeal cheboxes which are saved binary in one field, but
>actually i don´t know how to access them for sql. i tried to do it that
way:
>
>AND checkboxfield&(checkboxnumber², 16 in this case)
>
>but this doesnt work

Try using something like this:

$st="select features from whatever where uid=" . $row["uid"];
			$rs = mysql_query ($st) or die ("Query $st failed");
			$rr = mysql_fetch_array($rs);
			$Features=$rr[0];
			$ValidFeatures=array();
			$k=1;
			$wfcounter = 0;
			for ($m=0; $m<10; $m++)
    {
    if ($Features & $k)
        {
        $ValidFeatures[$m]=1;
        }
    else
        {
        $ValidFeatures[$m]=0;
        }
    $k *= 2;
    }

This will fill the array $ValidFeatures bitwise out of a 10bit value in the
database.

Joey






More information about the TYPO3-dev mailing list