Senthilkumar Posted August 10, 2023 Share Posted August 10, 2023 Dear Team, I am having Mysql databse table in the name of fieldtable. My table looks bellow image I want to fetch the data from this table where the value is 1 and display on my PHP table row wise How cani display the data like above picture. Can any one help me this Quote Link to comment Share on other sites More sharing options...
Barand Posted August 10, 2023 Share Posted August 10, 2023 If you had normalized your tables correctly you would already have the data in this format SELECT id , name , month , 'Field1' as field FROM senthil WHERE field1 = 1 UNION SELECT id , name , month , 'Field2' as field FROM senthil WHERE field2 = 1 UNION SELECT id , name , month , 'Field3' as field FROM senthil WHERE field3 = 1 UNION SELECT id , name , month , 'Field4' as field FROM senthil WHERE field4 = 1 ORDER BY id, field Quote Link to comment Share on other sites More sharing options...
Barand Posted August 10, 2023 Share Posted August 10, 2023 Alternative php solution $res = $pdo->query("SELECT id , name , month , field1 , field2 , field3 , field4 FROM senthil ORDER BY id "); $tdata = ''; foreach ($res as $r) { $flds = array_slice($r,3); foreach ($flds as $k => $v) { if ($v) { $tdata .= "<tr><td>{$r['name']}</td><td>{$r['month']}</td><td>$k</td></tr>\n"; } } } Quote Link to comment Share on other sites More sharing options...
Senthilkumar Posted August 10, 2023 Author Share Posted August 10, 2023 Dear Barand, Thanks for your support. it is working ap per my requirement Quote Link to comment 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.