thara Posted July 23, 2015 Share Posted July 23, 2015 (edited) I have a set of items to select from mysql. And then I want to display these items on my page with different 'markup`.This is how my HTML look like for each item. <ul class='unstyled main-facilities row'> <li class='info-facility-item '> <span class='fa-stack'> <i class='fa fa-square fa-stack-2x'></i> <i class='fa fa fa-cutlery fa-stack-1x fa-inverse'></i> </span> Item-01 </li> <li class='info-facility-item '> <span class='fa-stack'> <i class='fa fa-square fa-stack-2x'></i> <i class='fa fa fa-rss fa-stack-1x fa-inverse'></i> </span> Item-02 </li> <li class='info-facility-item '> <span class='fa-stack'> <i class='fa fa-square fa-stack-2x'></i> <i class='fa fa-refresh fa-stack-1x fa-inverse'></i> </span> Item-03 </li> ... ... ... </ul> If I have same markup for each item, then I can do it like this: // Fetch all the records: while ($stmt->fetch()) { $result = "<li class='info-facility-item '>\n"; $result .= " <span class='fa-stack'>\n"; $result .= " <i class='fa fa-square fa-stack-2x'></i>\n"; $result .= " <i class='fa fa fa-rss fa-stack-1x fa-inverse'></i>\n"; $result .= " </span>{$item}\n"; $result .= "</li>\n"; $items[] = $result; } } But I am not sure how to modify my `while` loop to render different markup for each item.Can anybody tell me is there a way to do this in PHP?Thank you. Edited July 23, 2015 by thara Quote Link to comment https://forums.phpfreaks.com/topic/297435-how-to-rendering-different-markup-for-each-record-from-mysql-select/ Share on other sites More sharing options...
requinix Posted July 23, 2015 Share Posted July 23, 2015 How would you, as a human, know what to change about the markup? How do you know which item gets two fas (really?) or whether it should be called "cutlery" or "rss" or "refresh"? Once you have that answered it shouldn't be hard to make the code do it. Quote Link to comment https://forums.phpfreaks.com/topic/297435-how-to-rendering-different-markup-for-each-record-from-mysql-select/#findComment-1517138 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.