I have a database and 1 table name .table: cranetype they have 4 fields (cf_did, cf_firstname, cf_comment, cf_cranetype).
below.
cf_did cf_firstname cf_comment cf_cranetype
1 Alexy tfhgfnjh 2,3
2 Thomas fdghfgh 11,6,3
3 Thomas cgjkjhl 5,6,11,3
4 Thomasxc cgjkjhl 1,6,9,4
5 Thomaseg fdghgh 11,12,3
6 Thomasm fsgdfgbd 11,6,3
7 Thomabs dgtrty 7,9,11
8 Rdgfghfdg bfdhh 1,3,4
9 Gngfdytyt eertret 1,6,3
10 Dvbgfj hfdhhyrtyr 6,3
11 Hnfhghyt bfgfdhg 11,6,3
12 Adgfdyh dfsdtrst 1
13 Rida gfhgfjgh 3,7,68
I have a selection box, they have values (1,2,3,4,...). If I select the value 1 from the selection box.
I want to check the database table field (cranetype) cf_cranetype.
For instance:
$sql= mysql_query("SELECT * FROM `cranetype` WHERE `cf_cranetype`='1'");
while($row=mysql_fetch_array($sql))
{
<?Php echo $row['cf_did'];?>
}
I need the output as follows:
if cf_cranetype =1.
4,8,9,12. (these are cf_did)
My code is:
$cranetype = $_POST['cranetype'];
$words = explode(',', $cranetype);
if (strlen($cranetype) > 0) {
$Where = '';
foreach ($words as $Item) {
$Where = "cf_cranetype LIKE '%$Item%' AND";
}
$Where = substr($Where, 0, -4);
$list_ul = "(SELECT * FROM cf_directory` WHERE $Where)";
$query = mysql_query($list_ul) or die(mysql_error());
}